When TypeScript projects use isolatedModules: true (required by Next.js,
SWC, and esbuild), type-only re-exports must use 'export type { }' syntax
instead of 'export { }'. Without this, users get TS1205 errors:
error TS1205: Re-exporting a type when 'isolatedModules' is enabled
requires using 'export type'.
This commit adds a new TypeScriptOptions.isolatedModules boolean (default
false, opt-in). When enabled with ESM named exports:
- renderExport() emits 'export type { ModelName }' for interfaces and
type aliases (any non-enum model), keeping 'export { }' for enums
since they are runtime values.
- renderCompleteModelDependencies() emits 'import type { ModelName }'
for cross-model dependencies that are type-only.
Enums are intentionally excluded from export type because they compile
to runtime JavaScript objects.
Fixes: asyncapi#2429
Description
Adds a new
isolatedModulesoption toTypeScriptOptions(default:false, opt-in). When set totruewith ESM named exports, the generator emitsexport type { }for type-only models (interfaces, type aliases) andimport type { }for cross-model dependencies.This fixes
TS1205: Re-exporting a type when 'isolatedModules' is enabled requires using 'export type'.errors that occur in Next.js, SWC, and esbuild projects.Before (broken with
isolatedModules: true):After (with
isolatedModules: true):Key design decisions:
export { }(neverexport type) because they compile to runtime JavaScript values.isolatedModules: falseby default) so existing users are unaffected.import type { }when the flag is enabled and the imported model is type-only.Usage:
Related Issue
Closes #2429
Checklist
npm run lint).npm run test).Additional Notes
TypeScriptDependencyManager.spec.tscovering all export/import type combinations.TypeScriptGenerator.spec.tsvalidating end-to-end output.