ember-cli-typescript integrates with Ember CLI through the standard addon system, providing hooks and methods that extend the build pipeline with TypeScript support.
The main addon class implements several key Ember CLI hooks to integrate TypeScript compilation and checking.
interface EmberCLIAddon {
/** Called when the addon is included in a build */
included(): void;
/** Provides custom CLI commands to the host application */
includedCommands(): Record<string, any> | undefined;
/** Returns the path to addon blueprints */
blueprintsPath(): string;
/** Registers middleware with the development server */
serverMiddleware(config: { app: Application; options?: any }): void;
/** Registers middleware with the test server */
testemMiddleware(app: Application, options?: any): void;
/** Runs after the build completes */
postBuild(): Promise<void>;
/** Sets up preprocessors in the registry */
setupPreprocessorRegistry(type: string, registry: PreprocessRegistry): void;
/** Filters which child addons should be included */
shouldIncludeChildAddon(addon: Addon): boolean;
}Called when the addon is included in the build. Performs initial setup and validation.
/**
* Main inclusion hook - sets up TypeScript integration
* Checks development setup, addon app files, and Babel version compatibility
* Starts typecheck worker for direct dependencies
*/
included(): void;Validation performed:
Provides CLI commands when the host is an Ember CLI addon.
/**
* Provides CLI commands for addon projects
* @returns Object with ts:precompile and ts:clean commands, or undefined for apps
*/
includedCommands(): Record<string, any> | undefined;Returns commands only for addon projects:
ts:precompile - Generate declaration files for publishingts:clean - Clean up generated filesSpecifies the location of addon blueprints for project setup.
/**
* Returns path to blueprint files
* @returns Absolute path to blueprints directory
*/
blueprintsPath(): string;Adds TypeScript error checking middleware to development and test servers.
/**
* Registers typecheck middleware with development server
* @param config - Server configuration with Express app and options
*/
serverMiddleware(config: { app: Application; options?: any }): void;
/**
* Registers typecheck middleware with test server
* @param app - Express application instance
* @param options - Optional configuration
*/
testemMiddleware(app: Application, options?: any): void;Middleware is skipped when serving from a specific path (e.g., proxy scenarios).
Performs type checking after builds complete.
/**
* Runs TypeScript checking after build completion
* @returns Promise that rejects if type checking fails
* @throws Error if type checking fails with noEmitOnError
*/
postBuild(): Promise<void>;Process:
Sets up file collision detection for JavaScript/TypeScript file conflicts.
/**
* Registers preprocessors with the build pipeline
* @param type - Registry type (only processes 'parent')
* @param registry - Preprocessor registry instance
*/
setupPreprocessorRegistry(type: string, registry: PreprocessRegistry): void;Adds collision detection preprocessor that warns about files with the same name but different extensions (.js vs .ts).
Controls which child addons are included in the build.
/**
* Determines whether a child addon should be included
* @param addon - Child addon to evaluate
* @returns false for test fixture addons, true otherwise
*/
shouldIncludeChildAddon(addon: Addon): boolean;Excludes test fixture addons (in-repo-a, in-repo-b) to avoid circular dependencies.
Helper function for creating type-safe Ember CLI addon configurations.
/**
* Configuration helper for defining Ember CLI addons with proper typing
* @param options - Addon configuration object
* @returns Same configuration object with proper typing
*/
function addon<T extends ExtendOptions<Addon>>(options: T & ExtendThisType<Addon, T>): T;Usage Example:
import { addon } from "ember-cli-typescript/ts/lib/utilities/ember-cli-entities";
export default addon({
name: "my-typescript-addon",
included() {
this._super.included.apply(this, arguments);
// Custom inclusion logic
},
// Other addon hooks...
});// Official addon name constant
const ADDON_NAME: "ember-cli-typescript";The addon maintains internal state and helper methods:
_typecheckWorker - Cached promise for the background typecheck worker_getTypecheckWorker() - Lazy initialization of typecheck worker_forkTypecheckWorker() - Creates new worker child process_addTypecheckMiddleware() - Adds middleware to Express applications