Skip to content

Conversation

@kwestground
Copy link
Contributor

@kwestground kwestground commented Jan 27, 2026

Summary

Enums are generated as TypeScript type aliases (export type MyEnum = ...),
so they must use import type for compatibility with verbatimModuleSyntax.

Problem

When using verbatimModuleSyntax: true (recommended for modern TypeScript projects),
the generated client fails at runtime with:

The requested module does not provide an export named 'MyEnum'

This is because enum types are imported without the type prefix.

Solution

Added check for CodeEnum in GetShouldUseTypeImport() method.

Related Issues

Fixes part of #2959

Reproduction Repository

Minimal reproduction: https://github.com/kwestground/kiota-enum-repro

git clone https://github.com/kwestground/kiota-enum-repro
cd kiota-enum-repro
npm install
npm run generate   # Generate with official Kiota
npm run build      # See TS1484 error

Checklist

  • Added unit test WritesImportTypeStatementForEnum
  • All existing tests pass

Enums are generated as TypeScript type aliases, so they must use
'import type' for compatibility with verbatimModuleSyntax.

Fixes part of microsoft#2959
Copilot AI review requested due to automatic review settings January 27, 2026 23:34
@kwestground kwestground requested a review from a team as a code owner January 27, 2026 23:34
@kwestground
Copy link
Contributor Author

@microsoft-github-policy-service agree

Copy link

Copilot AI left a 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 CodeEnum in GetShouldUseTypeImport() method to return true for enum types
  • Added comprehensive unit test WritesImportTypeStatementForEnum following 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.

Copy link
Member

@baywet baywet left a 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)

@kwestground kwestground requested a review from baywet January 28, 2026 23:31
@gavinbarron gavinbarron enabled auto-merge (squash) January 29, 2026 02:33
Copy link
Member

@baywet baywet left a 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!

@gavinbarron gavinbarron merged commit 59e5d0c into microsoft:main Jan 29, 2026
290 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants