fix: include const enum in type exports #486
Merged
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
This PR fixes auto-import handling for
const enumdeclarations.Closes nuxt/nuxt#33780
Problem
When using
const enumin Nuxt'sshared/directory, the auto-import system fails to properly resolve them. While regularenumdeclarations work correctly,const enumwas not being treated as both a value and a type export.The root cause is that
mllycorrectly distinguishes betweenenumandconst enumas separatedeclarationTypevalues, but unimport only handled the'enum'case.Solution
Add
const enumalongsideenumandclassin the three places where we check for declarations that need to be exported as both value and type:dedupeDtsExports()- Keep both value and type exports in.d.tsgenerationscanExports()- Generate both value and type imports when scanningdedupeImports()- Don't dedupe enum/class imports (they need both)This is consistent with how
enumandclassare already handled, since all three are TypeScript constructs that exist both at runtime (as values) and at compile-time (as types).Context
I'm a Nuxt collaborator and encountered this issue while investigating the linked Nuxt bug report. The fix is minimal and follows the existing pattern established for
enumandclass.