-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
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 thepackage.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: