The create_module_declaration function is the core engine for generating bundled .d.ts files. It performs a three-step process: discovering included modules via dependency tracing, tree-shaking unused declarations, and generating the final TypeScript declaration code. It handles external imports, namespace imports, and re-mapping identifiers to ensure that only the public API is exposed in the resulting declaration file.
Parameters
| Parameter | Type | Description |
|---|
id | string | The module identifier (e.g., the package name) for the declare module 'id' block. |
entry | string | The entry point file path used to start the dependency discovery. |
created | Record<string, string> | A map of already created files/modules. |
resolve | (file: string, specifier: string) => string | null | A resolver function to locate modules. |
options | object | Configuration options. |
Options
| Option | Type | Default | Description |
|---|
stripInternal | boolean | undefined | If true, declarations marked as internal (using @internal or similar) and their properties will be removed from the output. |
Returns
An object containing:
content: The generated .d.ts file string.mappings: A Map<string, Mapping> containing source mappings for the generated declarations.ambient: An array of ModuleReference[] representing ambient imports.
/**
* @param {string} id
* @param {string} entry
* @param {Record<string, string>} created
* @param {(file: string, specifier: string) => string | null} resolve
* @param {{ stripInternal?: boolean }} options
* @returns {{
* content: string;
* mappings: Map<string, Mapping>;
* ambient: ModuleReference[];
* }}
*/
export function create_module_declaration(id, entry, created, resolve, options) {
// ... implementation
}