fix: support const enums from adjacent .d.ts files - #833
Open
mrpmohiburrahman wants to merge 1 commit into
Open
mrpmohiburrahman wants to merge 1 commit into
mrpmohiburrahman wants to merge 1 commit into
Conversation
tsc inlines const enum members into each consumer at compile time, so the emitted .js never exports them. tsx transforms one file at a time and does not read .d.ts, so the identifier reaches runtime and fails there. Read the .d.ts beside a .js module, extract its exported const enums with esbuild, and append them to the module source. Fixing the imported side covers every import form at once. Fixes privatenumber#321
This branch has not been deployed
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.
Problem
tscinlinesconst enummembers at compile time, so the emitted.jsnever exports them. tsx transforms one file at a time and does not read.d.ts, so the identifier reaches runtime.With
some-lib/index.d.tsdeclaring:a named import fails:
A namespace import yields
undefinedinstead of throwing.Changes
When an ESM
.jshas an adjacent.d.ts, its exportedconst enums are run through esbuild and appended to the module source. Fixing the imported side covers named, namespace and default imports at once.existsSyncguard.Scoped to the adjacent
.d.ts, per your comment on #321. Still unsupported:typeRoots, global ambient declarations,require()through the CommonJS loader,declare const enum X {}paired with a separateexport { X }, and.mjsbeside a.d.tsrather than.d.mts.One divergence from
tsc: it erases the enum, this materialises it, so the name appears inObject.keys(namespace).10 tests added, each confirmed failing before the change. Suite 187 → 197 passing, with the same 3 pre-existing failures. Lint and type-check clean.
Fixes #321