Skip to content

Conversation

@Flo0806
Copy link
Contributor

@Flo0806 Flo0806 commented Dec 13, 2025

Summary

This PR fixes auto-import handling for const enum declarations.

Closes nuxt/nuxt#33780

Problem

When using const enum in Nuxt's shared/ directory, the auto-import system fails to properly resolve them. While regular enum declarations work correctly, const enum was not being treated as both a value and a type export.

The root cause is that mlly correctly distinguishes between enum and const enum as separate declarationType values, but unimport only handled the 'enum' case.

Solution

Add const enum alongside enum and class in the three places where we check for declarations that need to be exported as both value and type:

  1. dedupeDtsExports() - Keep both value and type exports in .d.ts generation
  2. scanExports() - Generate both value and type imports when scanning
  3. dedupeImports() - Don't dedupe enum/class imports (they need both)

This is consistent with how enum and class are 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 enum and class.

@antfu antfu merged commit 28e8802 into unjs:main Dec 14, 2025
3 checks passed
@codecov
Copy link

codecov bot commented Dec 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.67%. Comparing base (a4a5e0a) to head (63a4002).
⚠️ Report is 141 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #486      +/-   ##
==========================================
- Coverage   98.73%   97.67%   -1.06%     
==========================================
  Files          14       15       +1     
  Lines        1817     1463     -354     
  Branches      374      478     +104     
==========================================
- Hits         1794     1429     -365     
- Misses         23       34      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

Nuxt does not auto-import const enums with the same behaviour as an import statement

2 participants