fix(TypeScript): use import type for enum types#7332
Merged
gavinbarron merged 4 commits intomicrosoft:mainfrom Jan 29, 2026
Merged
fix(TypeScript): use import type for enum types#7332gavinbarron merged 4 commits intomicrosoft:mainfrom
gavinbarron merged 4 commits intomicrosoft:mainfrom
Conversation
Enums are generated as TypeScript type aliases, so they must use 'import type' for compatibility with verbatimModuleSyntax. Fixes part of microsoft#2959
Contributor
Author
|
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
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
requested changes
Jan 28, 2026
Member
baywet
left a comment
There was a problem hiding this comment.
Thanks for the contribution!
Can you please also add a changelog entry? (unreleased, changed)
gavinbarron
approved these changes
Jan 29, 2026
baywet
approved these changes
Jan 29, 2026
Member
baywet
left a comment
There was a problem hiding this comment.
Thank you for making the changes!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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