types: Export types in a way compatible with TypeScript "module": "nodenext"
#72
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Thanks for maintaining this useful package!
Because the code in
index.js
uses a commonjs-stylemodule.exports = function ...
whileindex.d.ts
uses an ESM-styleexport default ...
, the type of the default export is not interpreted as desired when using TypeScript 4.7 with config"module": "node16"
(also known asnodenext
, which is currently in RC). This PR suggests using the same style of default export in both places, which works on all versions & settings of TypeScript I have tested.I have tested this change using both TypeScript 4.7 RC with the new module setting and some of the older module settings, as well as testing with TypeScript 4.6 on the same older module setting choices, and all those cases now correctly interpret the type of the default export. I also tested to make sure that the type
SnakeCaseKeys
is still exported properly and passing thetsd
tests.I ended up chatting with somebody who knows more about this stuff than me in the TypeScript Discord, but here's some additional background reading about the reasons behind this change: