type-export-builder
v1.1.0
Published
Generate complete public type exports from your runtime public API
Maintainers
Readme
type-export-builder
Generate complete public type exports from your runtime public API.
type-export-builder analyzes your runtime public entry files, discovers all required type dependencies, and generates a dedicated public type module that consumers can import safely.
Instead of manually maintaining large public-types.ts files, the tool automatically resolves the required declarations while preventing accidental runtime API exposure.
Features
- Generate public type modules automatically.
- Analyze complete type dependency graphs.
- Works directly with TypeScript projects.
- Supports complex type expressions.
- Prevents accidental runtime API leaks.
- Built on top of the TypeScript compiler via ts-morph.
Installation
npm install --save-dev type-export-builderor
pnpm add -D type-export-builderUsage
type-export-builder generate \
-p src/public.ts \
-t tsconfig.jsonGenerate public types while also following class instantiation dependencies:
type-export-builder generate \
-p src/public.ts \
-iCLI
| Option | Description |
| ---------------------------- | --------------------------------------------- |
| -p, --public <file...> | Runtime public entry files. |
| -t, --tsconfig <file> | Path to tsconfig.json. |
| -i, --follow-instantiation | Also follow class instantiation dependencies. |
Example
Runtime public entry:
// public.ts
export { UserService };
export { createUser };Generated public type module:
export type { User } from './models/User';
export type { UserOptions } from './models/UserOptions';
export type { UserResult } from './models/UserResult';
export type { CreateUserOptions } from './models/CreateUserOptions';Dependency Resolution
The generator automatically resolves type dependencies required by your public API.
Supported examples include:
- Interfaces
- Classes
- Type aliases
- Enums
- Functions
- Variables
- Generic types
- Conditional types
- Indexed access types
- Template literal types
keyoftypeofinfer- Utility types (
Pick,Omit,Readonly,Partial,Required, etc.)
Runtime Dependency
By default, the generator only follows usage dependencies.
Class instantiation dependencies (such as constructor parameter graphs) are not followed automatically to avoid exposing internal runtime implementation details.
Enable them explicitly with:
type-export-builder generate --follow-instantiationNot Supported
Runtime object dependency graphs are not analyzed.
This includes patterns such as:
export const UserType = {
User: 'user',
} as const;
export interface Options {
type: typeof UserType;
}If a runtime declaration is part of your public API, export it explicitly from your runtime public entry.
Requirements
- Node.js 18+
- TypeScript project
tsconfig.json
License
MIT Yuki Akai
