Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api-extractor] Add support for new TS declaration format when using module resolution 'bundler' or 'nodenext' #4952

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bartvandenende-wm
Copy link
Contributor

@bartvandenende-wm bartvandenende-wm commented Oct 1, 2024

Summary

Add support for new TS declaration format when using module resolution 'bundler' or 'nodenext'

fixes #4899

Details

TS 5.x started to support new moduleResolution bundler and nodenext (or node16) which changes the behaviour of TS declaration files for arbitrary extensions like .json and .css.

By default, this import will raise an error to let you know that TypeScript doesn’t understand this file type and your runtime might not support importing it. But if you’ve configured your runtime or bundler to handle it, you can suppress the error with the new --allowArbitraryExtensions compiler option.

Note that historically, a similar effect has often been achievable by adding a declaration file named app.css.d.ts instead of app.d.css.ts - however, this just worked through Node’s require resolution rules for CommonJS. Strictly speaking, the former is interpreted as a declaration file for a JavaScript file named app.css.js. Because relative files imports need to include extensions in Node’s ESM support, TypeScript would error on our example in an ESM file under --moduleResolution node16 or nodenext

By enabling the TS allowArbitraryExtensions setting, declaration files can be imported with the new module resolutions but are required to follow the {file basename}.d.{extension}.ts pattern.

This PR updates the regex in ExtractorConfig which detect if a file is a declaration file to be inclusive of the new pattern.

How it was tested

unit test

Impacted documentation

N/A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Needs triage
Development

Successfully merging this pull request may close these issues.

[api-extractor] Support new TS .d.json.ts declaration pattern
1 participant