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] Support new TS .d.json.ts declaration pattern #4899

Open
bartvandenende-wm opened this issue Aug 22, 2024 · 5 comments · May be fixed by #4952
Open

[api-extractor] Support new TS .d.json.ts declaration pattern #4899

bartvandenende-wm opened this issue Aug 22, 2024 · 5 comments · May be fixed by #4952

Comments

@bartvandenende-wm
Copy link
Contributor

Summary

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 but are required to follow the {file basename}.d.{extension}.ts pattern which is not supported yet by API-Extractor.

Repro steps

  1. change the moduleResolution to bundler and allowArbitraryExtensions to true in the tsconfig.json file.
  2. convert any .json.d.ts file extensions in the repo to .d.json.ts

Expected result:

API extractor to not throw warnings or errors

Actual result:

API extractor shows a ae-wrong-input-file-type warning for the files with .d.json.ts extension.

Details

This can likely be fixed by updating the below regex with the new pattern.

private static readonly _declarationFileExtensionRegExp: RegExp = /\.d\.(c|m)?ts$/i;

(unrelated to API extractor, but I also suspect the heft-sass-plugin is impacted since it generates css.d.ts files)

Standard questions

Please answer these questions to help us investigate your issue more quickly:

Question Answer
@microsoft/api-extractor version? 7.47.7
Operating system? Mac
API Extractor scenario? N/A
Would you consider contributing a PR? Yes
TypeScript compiler version? v5.3.3
Node.js version (node -v)? v18.16.1
@Aldocapurro
Copy link

[email protected]

@Aldocapurro
Copy link

Hola

1 similar comment
@Aldocapurro
Copy link

Hola

@iclanton
Copy link
Member

iclanton commented Sep 9, 2024

@octogonz - want to take a look at this?

@Aldocapurro
Copy link

Me puedes ayudar ? Como estas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: AE/AD
3 participants