TS: fix 'node16'/'nodenext' compatibility, and emit type declarations for .ts files with external exports under dist/types#1987
Merged
Conversation
99413ff to
cd6ff60
Compare
155cf67 to
6375914
Compare
2550e39 to
0cba135
Compare
twiss
approved these changes
Apr 30, 2026
So that exported TS types are compatible with 'node16' module resolution
Needed for consuming TS types
With better-docs integration, .ts files can be parsed by jsdoc, so separate module declarations can be dropped
…ublish them under `dist/types` This change makes it possible to easily expose types from internal .ts files. This is achieved by adding a TS compilation step which generates .d.ts files from .ts ones. Additionally, a copying step is needed for existing .d.ts files, which are not automatically moved to the outDir by tsc. The dist types will still only include those exported by the index files. Other tried approaches (to e.g. avoid the manual copying step) that were not viable: - generating a single .d.ts bundle is not supported by tsc, and other tools/plugins are either deprecated or (in the case of `rollup-plugin-dts`) failed to process our source code due to unsupported JS syntax - relying on the `rollup-typescript` plugin to emit declarations felt overly messy to configure and potentially unreliable as it generated declarations for .js files as well - renaming existing .d.ts to .ts (alongside .js ones) is not an option since it results in an empty output for the corresponding modules on Rollup compilation, as the .js source files are ignored.
Since the former is needed for mocha, and we want to avoid keeping two almost redundant dependencies
TS v5.0 is required as it's the first to support imports using .ts extensions
0cba135 to
91dfc38
Compare
larabr
added a commit
to larabr/openpgpjs
that referenced
this pull request
Apr 30, 2026
Broken in openpgpjs#1987
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.
This MR makes it possible to write exported modules in TS, as the corresponding type definitions are now automatically generated.
It also fixes consuming TS types when setting
'node16'or'nodenext'as TS module resolution strategies (supersedes #1983), which require explicit file extensions.See commits for more details.