Skip to content

TS: fix 'node16'/'nodenext' compatibility, and emit type declarations for .ts files with external exports under dist/types#1987

Merged
larabr merged 6 commits into
openpgpjs:mainfrom
larabr:explicit-extensions
Apr 30, 2026
Merged

TS: fix 'node16'/'nodenext' compatibility, and emit type declarations for .ts files with external exports under dist/types#1987
larabr merged 6 commits into
openpgpjs:mainfrom
larabr:explicit-extensions

Conversation

@larabr

@larabr larabr commented Mar 17, 2026

Copy link
Copy Markdown
Collaborator

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.

@larabr larabr closed this Mar 17, 2026
@larabr larabr force-pushed the explicit-extensions branch from 99413ff to cd6ff60 Compare March 17, 2026 15:39
@larabr larabr reopened this Mar 17, 2026
@larabr larabr force-pushed the explicit-extensions branch 2 times, most recently from 155cf67 to 6375914 Compare March 17, 2026 16:00
@larabr larabr force-pushed the explicit-extensions branch 2 times, most recently from 2550e39 to 0cba135 Compare March 18, 2026 13:28
larabr added 6 commits April 30, 2026 22:57
So that exported TS types are compatible with 'node16' module resolution
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
@larabr larabr force-pushed the explicit-extensions branch from 0cba135 to 91dfc38 Compare April 30, 2026 20:57
@larabr larabr merged commit f3c3330 into openpgpjs:main Apr 30, 2026
24 of 26 checks passed
larabr added a commit to larabr/openpgpjs that referenced this pull request Apr 30, 2026
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.

2 participants