-
Notifications
You must be signed in to change notification settings - Fork 299
fix(TypeScript): use import type for enum types #7332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(TypeScript): use import type for enum types #7332
Conversation
Enums are generated as TypeScript type aliases, so they must use 'import type' for compatibility with verbatimModuleSyntax. Fixes part of microsoft#2959
|
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a critical issue where TypeScript enum imports fail at runtime when using verbatimModuleSyntax: true by ensuring enum types use import type syntax.
Changes:
- Added check for
CodeEnuminGetShouldUseTypeImport()method to return true for enum types - Added comprehensive unit test
WritesImportTypeStatementForEnumfollowing existing test patterns
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Kiota.Builder/Writers/TypeScript/CodeUsingWriter.cs | Added CodeEnum check in GetShouldUseTypeImport() to ensure enums use import type syntax, with explanatory comments referencing the issue |
| tests/Kiota.Builder.Tests/Writers/TypeScript/CodeUsingWriterTests.cs | Added test WritesImportTypeStatementForEnum that verifies enums generate import type statements, following the same pattern as existing tests for interfaces and models |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
baywet
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution!
Can you please also add a changelog entry? (unreleased, changed)
baywet
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for making the changes!
Summary
Enums are generated as TypeScript type aliases (
export type MyEnum = ...),so they must use
import typefor compatibility withverbatimModuleSyntax.Problem
When using
verbatimModuleSyntax: true(recommended for modern TypeScript projects),the generated client fails at runtime with:
This is because enum types are imported without the
typeprefix.Solution
Added check for
CodeEnuminGetShouldUseTypeImport()method.Related Issues
Fixes part of #2959
Reproduction Repository
Minimal reproduction: https://github.com/kwestground/kiota-enum-repro
Checklist
WritesImportTypeStatementForEnum