fix: support TypeScript 7 declaration builds - #1409
Open
ljh12138164 wants to merge 2 commits into
Open
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
|
@ljh12138164 is attempting to deploy a commit to the EGOIST's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
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.
fix: support TypeScript 7 declaration builds
Closes #1408.
Summary
This PR adds TypeScript 7 support for declaration builds while preserving the
existing behavior for TypeScript 4.5 through 6.
TypeScript 7 projects can now use
--dtsand--experimental-dtsby installingthe official
@typescript/typescript6compatibility package. Projects that donot generate declarations do not need the compatibility package.
Problem
TypeScript 7 currently does not expose the legacy Compiler API used by tsup and
rollup-plugin-dts. With TypeScript 7.0.2 anddts: true, tsup 8.5.1 thereforefails while initializing the declaration build. This is the failure reported in
#1408.
For example, APIs used by the existing declaration paths are unavailable from
the TypeScript 7 package:
createProgramcreateCompilerHostparseJsonConfigFileContentsysThe JavaScript bundling path does not require these APIs and should continue to
work without any additional dependency.
Implementation
Upgrade
rollup-plugin-dtsrollup-plugin-dtsis upgraded from 6.1.1 to 6.5.1. This includes thecompatibility work from
rollup-plugin-dts PR #401:
typescriptpackage dynamically.createProgram.@typescript/typescript6when the installed TypeScript packagedoes not expose the Compiler API.
missing.
Add a shared TypeScript API loader
Upgrading
rollup-plugin-dtsalone is not sufficient because tsup also uses theCompiler API directly in its standard and experimental declaration paths.
This PR adds a shared
loadTypeScript()helper that follows the same capabilitydetection strategy:
The loader is used by both:
--dtsimplementation;--experimental-dtsimplementation.Loading remains lazy. The compatibility API is requested only after a
declaration build starts, so TypeScript 7 projects that only bundle JavaScript
do not need
@typescript/typescript6.Declare the compatibility package
@typescript/typescript6is added as an optional peer dependency. TypeScript4.5 through 6 continue using their installed Compiler API. TypeScript 7 users
that generate declarations install both packages:
The project still compiles with TypeScript 7. The TypeScript 6 compatibility API
is used only by declaration tooling. This follows Microsoft's documented
TypeScript 7 transition guidance.
Compatibility
typescript@typescript/typescript6Tests
Added coverage for:
@typescript/typescript6for TypeScript 7;Full test result:
References