Skip to content

fix: support TypeScript 7 declaration builds - #1409

Open
ljh12138164 wants to merge 2 commits into
egoist:mainfrom
ljh12138164:fix/typescript-7-dts
Open

fix: support TypeScript 7 declaration builds#1409
ljh12138164 wants to merge 2 commits into
egoist:mainfrom
ljh12138164:fix/typescript-7-dts

Conversation

@ljh12138164

Copy link
Copy Markdown

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 --dts and --experimental-dts by installing
the official @typescript/typescript6 compatibility package. Projects that do
not 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 and dts: true, tsup 8.5.1 therefore
fails 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:

  • createProgram
  • createCompilerHost
  • parseJsonConfigFileContent
  • sys

The JavaScript bundling path does not require these APIs and should continue to
work without any additional dependency.

Implementation

Upgrade rollup-plugin-dts

rollup-plugin-dts is upgraded from 6.1.1 to 6.5.1. This includes the
compatibility work from
rollup-plugin-dts PR #401:

  1. Load the project's typescript package dynamically.
  2. Use it directly when it exposes createProgram.
  3. Fall back to @typescript/typescript6 when the installed TypeScript package
    does not expose the Compiler API.
  4. Provide an actionable error when the compatibility package is required but
    missing.

Add a shared TypeScript API loader

Upgrading rollup-plugin-dts alone is not sufficient because tsup also uses the
Compiler API directly in its standard and experimental declaration paths.

This PR adds a shared loadTypeScript() helper that follows the same capability
detection strategy:

const typescript = require('typescript')

if (typeof typescript.createProgram === 'function') {
  return typescript
}

return require('@typescript/typescript6')

The loader is used by both:

  • the Rollup-based --dts implementation;
  • the TypeScript/API Extractor-based --experimental-dts implementation.

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/typescript6 is added as an optional peer dependency. TypeScript
4.5 through 6 continue using their installed Compiler API. TypeScript 7 users
that generate declarations install both packages:

npm install --save-dev typescript@7 @typescript/typescript6

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

Project setup Declaration API used Extra package required
TypeScript 4.5-6 with DTS Installed typescript No
TypeScript 7 with DTS @typescript/typescript6 Yes
TypeScript 7 without DTS None No

Tests

Added coverage for:

  • using the Compiler API from TypeScript 4.5 through 6;
  • falling back to @typescript/typescript6 for TypeScript 7;
  • reporting an actionable error when the fallback is missing;
  • running a TypeScript 7 build without declarations and without the fallback;
  • running an end-to-end TypeScript 7 declaration build with the fallback.

Full test result:

Test Files  11 passed (11)
Tests       100 passed (100)

References

@codesandbox

codesandbox Bot commented Aug 8, 2026

Copy link
Copy Markdown

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@vercel

vercel Bot commented Aug 8, 2026

Copy link
Copy Markdown

@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.

@socket-security

socket-security Bot commented Aug 8, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​typescript/​typescript6@​6.0.2621005592100
Addedrollup-plugin-dts@​6.5.1991001009170

View full report

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.

Add Support to Typescript V7

1 participant