-
-
Notifications
You must be signed in to change notification settings - Fork 229
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Why do we need this improvement?
When generating TypeScript models with tsModelType: interface, the generator produces:
interface ErrorPayload {
type: "error";
message: string;
}
export { ErrorPayload }; This syntax is incompatible with TypeScript's isolatedModules: true compiler option, which is required by modern frameworks like Next.js. With isolatedModules enabled, TypeScript requires type-only exports to use the export type syntax:
interface ErrorPayload {
type: "error";
message: string;
}
export type { ErrorPayload }; // Required for isolatedModules Error Message
error TS1205: Re-exporting a type when 'isolatedModules' is enabled requires using 'export type'.
How will this change help?
Use Case
- Next.js projects (requires isolatedModules: true)
- Any TypeScript project using isolatedModules for faster builds
- Projects using SWC or esbuild which require isolatedModules-compatible code
Screenshots
No response
How could it be implemented/designed?
Add a new TypeScript-specific option (e.g., --tsExportTypeOnly or extend --tsExportType with a type value) that generates export type { } for interfaces while keeping export { } for enums (which are
runtime values).
For interfaces:
export type { ErrorPayload };
For enums (unchanged):
export { ErrorCode };
Affected Code
The export logic is in TypeScriptDependencyManager.renderExport():
// Current implementation (ESM named exports):
return `export { ${model.name} };`;
// Proposed change when type-only export is enabled:
if (options.typeOnlyExport && model.type === 'interface') {
return `export type { ${model.name} };`;
}
return `export { ${model.name} };`; Environment
- Modelina version: latest (via @asyncapi/cli v6.0.0)
- TypeScript version: 5.x
- AsyncAPI CLI command:
asyncapi generate models typescript spec.yaml --tsModelType interface --tsEnumType enum --tsExportType named
Workaround
Currently requires post-processing generated files to convert export { } to export type { } for interfaces, which is error-prone and adds build complexity.
🚧 Breaking changes
Yes
👀 Have you checked for similar open issues?
- I checked and didn't find a similar issue
🏢 Have you read the Contributing Guidelines?
- I have read the Contributing Guidelines
Are you willing to work on this issue?
None
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request