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

types: Export types in a way compatible with TypeScript "module": "nodenext" #72

Merged
merged 2 commits into from
May 13, 2022

Conversation

jming422
Copy link
Contributor

Thanks for maintaining this useful package!

Because the code in index.js uses a commonjs-style module.exports = function ... while index.d.ts uses an ESM-style export default ..., the type of the default export is not interpreted as desired when using TypeScript 4.7 with config "module": "node16" (also known as nodenext, 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 the tsd 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:

jming422 added 2 commits May 12, 2022 22:59
Because the code uses a commonjs-style `module.exports = function ...`
while the types use an ESM-style `export default ...`, the type of the
default export is not intrepreted correctly when using TypeScript 4.7
with `"module": "node16"` (which is currently in RC). Using the same
style of default export in both places works though!
Interestingly, I found that I could correctly import the type
SnakeCaseKeys without issue in a trivial TS project set to import from
this branch of snakecase-keys, both before and after this change. But
tsd was complaining on the last commit and it is satisfied now, with no
changes to the test itself.
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

Successfully merging this pull request may close these issues.

2 participants