This document provides comprehensive documentation for @qlik/dts-bundler, covering both the JavaScript/TypeScript API and the CLI tool.
Bundle TypeScript declaration files into a single output string.
import { bundleTypes } from "@qlik/dts-bundler";
const output = bundleTypes(options);| Parameter | Type | Description |
|---|---|---|
options |
BundleDtsOptions |
Configuration options object |
string — The bundled TypeScript declaration content.
Error— Whenentryoption is missingError— When entry file does not exist
import { bundleTypes } from "@qlik/dts-bundler";
import fs from "fs";
const bundled = bundleTypes({
entry: "./src/index.ts",
});
fs.writeFileSync("./dist/index.d.ts", bundled);import { bundleTypes } from "@qlik/dts-bundler";
import fs from "fs";
const bundled = bundleTypes({
entry: "./src/index.ts",
inlinedLibraries: ["@my-org/internal-types", "@my-org/shared"],
allowedTypesLibraries: ["node"],
inlineDeclareGlobals: true,
inlineDeclareExternals: true,
sortNodes: true,
noBanner: false,
});
fs.writeFileSync("./dist/index.d.ts", bundled);Type: string
Required: Yes
The entry TypeScript file path. This is the starting point for bundling. The bundler will resolve and process all imports from this file.
bundleTypes({
entry: "./src/types.ts",
});The path can be:
- A relative path (resolved from the current working directory)
- An absolute path
- A
.ts,.tsx,.mts,.cts, or.d.tsfile
Type: string[]
Default: []
Array of npm package names whose types should be inlined into the bundle instead of remaining as external imports.
bundleTypes({
entry: "./src/index.ts",
inlinedLibraries: ["@my-org/types", "@my-org/utils"],
});Use cases:
- Bundling internal/private packages that shouldn't be dependencies
- Creating standalone type definitions
- Monorepo packages that should be flattened
Notes:
- Use the full package name including scope (e.g.,
@scope/package) - Subpaths are supported (e.g.,
@scope/package/submodule)
Type: string[]
Default: undefined
Array of @types/* package names that should be referenced via triple-slash directives instead of being inlined or imported.
bundleTypes({
entry: "./src/index.ts",
allowedTypesLibraries: ["node", "react"],
});Output includes:
/// <reference types="node" />
/// <reference types="react" />Use cases:
- When consumers should install
@types/*packages separately - For common environment types like
@types/node
Type: string[]
Default: undefined
Array of library names that should explicitly remain as regular imports in the output, regardless of other settings.
bundleTypes({
entry: "./src/index.ts",
importedLibraries: ["react", "lodash"],
});Use cases:
- Ensuring specific dependencies remain as peer dependencies
- Preventing accidental inlining of large libraries
Type: boolean
Default: false
Whether to inline declare global { ... } blocks from imported files into the bundle.
bundleTypes({
entry: "./src/index.ts",
inlineDeclareGlobals: true,
});When true: Global augmentations from all processed files are included in the output.
When false: Global declarations are omitted (they may need to be in a separate file).
Example input:
// In an imported file
declare global {
interface Window {
myApp: MyAppType;
}
}Type: boolean
Default: false
Whether to inline declare module "..." blocks for external modules.
bundleTypes({
entry: "./src/index.ts",
inlineDeclareExternals: true,
});When true: Module augmentations for external packages are included.
Example input:
// In an imported file
declare module "express" {
interface Request {
user?: User;
}
}Type: boolean
Default: false
Whether to automatically export types that are referenced by exported declarations but not explicitly exported themselves.
bundleTypes({
entry: "./src/index.ts",
exportReferencedTypes: true,
});Example:
// Input
interface InternalType {
id: string;
}
export interface PublicType {
data: InternalType;
}
// Output with exportReferencedTypes: true
export interface InternalType {
id: string;
}
export interface PublicType {
data: InternalType;
}
// Output with exportReferencedTypes: false
interface InternalType {
id: string;
}
export interface PublicType {
data: InternalType;
}Type: boolean
Default: false
Whether to exclude the generated banner comment from the output.
bundleTypes({
entry: "./src/index.ts",
noBanner: true,
});When false (default): Output includes a banner:
// Generated by @qlik/dts-bundlerWhen true: No banner is added.
Type: boolean
Default: false
Whether to sort declarations alphabetically in the output.
bundleTypes({
entry: "./src/index.ts",
sortNodes: true,
});Use cases:
- Consistent output regardless of import order
- Easier diffing between versions
- Alphabetical organization preference
Type: string
Default: undefined
UMD module name to include in the output. When specified, generates a UMD-compatible declaration.
bundleTypes({
entry: "./src/index.ts",
umdModuleName: "MyLibrary",
});Output includes:
export as namespace MyLibrary;Type: boolean
Default: false
Whether to respect the preserveConstEnums setting from tsconfig.json.
bundleTypes({
entry: "./src/index.ts",
respectPreserveConstEnum: true,
});When true: If tsconfig.json has "preserveConstEnums": true, const enums are preserved as-is.
When false: Const enums may be inlined regardless of tsconfig settings.
The CLI tool is available as bundle-types after installation.
bundle-types [options]| Option | Alias | Type | Required | Description |
|---|---|---|---|---|
--entry |
-e |
string |
Yes | Entry TypeScript file to bundle |
--output |
-o |
string |
Yes | Output file path for bundled types |
--inlinedLibraries |
-i |
string |
No | Comma-separated list of npm packages to inline |
--help |
-h |
— | No | Show help message |
Bundle local imports only:
bundle-types -e ./src/types.ts -o ./dist/bundle.d.tsBundle with specific npm packages inlined:
bundle-types \
-e ./src/types.ts \
-o ./dist/bundle.d.ts \
-i @my-org/types,@my-org/utilsSeparate multiple libraries with commas (no spaces):
bundle-types -e ./src/index.ts -o ./dist/index.d.ts -i pkg1,pkg2,@scope/pkg3Add to your package.json:
{
"scripts": {
"build:types": "bundle-types -e ./src/index.ts -o ./dist/index.d.ts"
}
}Then run:
npm run build:typesChain with other build commands:
tsc && bundle-types -e ./src/index.ts -o ./dist/index.d.tsThe bundler automatically reads and respects your tsconfig.json settings:
- Path mappings (
paths,baseUrl) — Resolved correctly - Module resolution (
moduleResolution) — Respected - Strict mode settings — Preserved in output
preserveConstEnums— Respected whenrespectPreserveConstEnumis enabled
The bundler looks for tsconfig.json in the directory of the entry file, walking up the directory tree if needed.
interface BundleDtsOptions {
/** Entry TypeScript file path (required) */
entry: string;
/** Array of library names to inline */
inlinedLibraries?: string[];
/** @types libraries to reference via triple-slash directives */
allowedTypesLibraries?: string[];
/** Libraries that should remain as regular imports */
importedLibraries?: string[];
/** Whether to inline declare global blocks */
inlineDeclareGlobals?: boolean;
/** Whether to inline declare module blocks for external modules */
inlineDeclareExternals?: boolean;
/** Whether to export referenced types automatically */
exportReferencedTypes?: boolean;
/** Whether to exclude the banner comment */
noBanner?: boolean;
/** Whether to sort nodes alphabetically */
sortNodes?: boolean;
/** UMD module name to output */
umdModuleName?: string;
/** Respect preserveConstEnums from tsconfig */
respectPreserveConstEnum?: boolean;
}