-
Notifications
You must be signed in to change notification settings - Fork 208
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
Add compatibility with TypeScript and ESM #429
Conversation
Thanks @jscheid. I will hold onto this pending 4.7 release and checking the results in various environments (and pending me taking the time to understand it fully 😄 ) |
I just ran into this today since I'm using NodeNext for my Typescript setup. If I understand it all correctly, the crux of the issue is that the existence of the
The current PR solves this by adding that {
"exports": {
".": {
// Just need to add the following line
"types": "./index.d.ts",
"require": "./index.js",
"default": "./index.mjs"
}
}
} In essence, that fixes the fact that the root-level |
Here's the diff I got when using diff --git a/node_modules/just-pick/package.json b/node_modules/just-pick/package.json
index 50223ce..256d586 100644
--- a/node_modules/just-pick/package.json
+++ b/node_modules/just-pick/package.json
@@ -7,7 +7,8 @@
"exports": {
".": {
"require": "./index.js",
- "default": "./index.mjs"
+ "default": "./index.mjs",
+ "types": "./index.d.ts"
}
},
"types": "index.d.ts", |
Hi @adam-coster. Sorry for the belated reply. This does sound like the best solution. |
This adds compatibility with TypeScript's Experimental Support for ECMAScript Modules in Node.js. I've seen the
package.json
syntax mentioned in microsoft/TypeScript#33079 and it solves the issue for me.It's meant as an example only, you might want to hold off merging this until TypeScript 4.7 is released. I'm not sure this will continue to work in the release. And if it does, you might want to do something similar for all the other packages in this repository. I've marked it as draft for these reasons.
Also, I haven't checked whether the syntax in
index.d.mts
would work with other TypeScript versions and configurations. If it does then it would be better to use a single file instead of bothindex.d.ts
andindex.d.mts
.And finally, I haven't checked whether TypeScript 4.7 without ESM support enabled also needs the different syntax. If so, it might be necessary to use the
typesVersion
setting.Fixes #428