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

Revisit TypeScript definitions for dual cjs/esm #1880

Closed
shadowspawn opened this issue May 11, 2023 · 1 comment
Closed

Revisit TypeScript definitions for dual cjs/esm #1880

shadowspawn opened this issue May 11, 2023 · 1 comment

Comments

@shadowspawn
Copy link
Collaborator

I think we got this technically wrong in #1704. Basically, we need a separate type definition file for each of cjs and esm. This is a common mistake and in our defence the documentation may have got clearer in the last year!

From https://www.typescriptlang.org/docs/handbook/esm-node.html

It’s important to note that the CommonJS entrypoint and the ES module entrypoint each needs its own declaration file, even if the contents are the same between them. Every declaration file is interpreted either as a CommonJS module or as an ES module, based on its file extension and the "type" field of the package.json, and this detected module kind must match the module kind that Node will detect for the corresponding JavaScript file for type checking to be correct.

Looking back, @ChocolateLoverRaj did make a second file when investigating, and just reexporting the cjs types is hopefully sufficient like in comment: #1703 (comment)

The TypeScript gurus actually suggest not having a "types" entry and just having type definition sitting beside the entry point. However, we have historically had the definitions tucked away in a folder and I'm ok with continuing with that.

Related links:

@shadowspawn shadowspawn added the pending release Merged into a branch for a future release, but not released yet label May 14, 2023
@shadowspawn
Copy link
Collaborator Author

Released in v11

@shadowspawn shadowspawn removed the pending release Merged into a branch for a future release, but not released yet label Jun 16, 2023
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

No branches or pull requests

1 participant