Fix generic type inference for cross-package imports in svelte-package #2837
+96
−3
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
When using
svelte-package
to compile Svelte components that import generic classes from external packages the generated.d.ts
files were losing generic type information and falling back toany
types.Example:
This issue only occurred with cross-package imports in monorepo environments where the generic class was defined in a separate package from where it was instantiated.
Root Cause
The issue was in
emitDts.ts
where the TypeScript compiler options used legacy Node10 module resolution (ModuleResolutionKind.Node10
). This older resolution strategy cannot properly resolve modern package.jsonexports
fields and workspace dependencies commonly used in monorepo setups, leading to failed module resolution and type inference fallbacks.Solution
Updated the module resolution:
This change allows the TypeScript compiler to:
exports
fields in package.jsonworkspace:*
)Testing
Added new test at
test/emitDts/samples/cross-package-generic-types/
that:.d.ts
files