-
-
Notifications
You must be signed in to change notification settings - Fork 252
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
fix: add types #248
fix: add types #248
Conversation
Huh, I have no reason to object to this, but I'm curious why it doesn't pull in types for you just by virtue of them being in the same folder as the module being loaded. I see them getting pulled in with typescript 4.9.3, what version are you using? |
The ESM build usings {
"extends": "./tsconfig-base.json",
"compilerOptions": {
"module": "esnext",
"outDir": "dist/mjs"
}
} So yeah, it's using |
PR-URL: isaacs#248 Credit: @unional Close: isaacs#248 Reviewed-by: @isaacs
Um, interesting. It is possible that it is improved in some newer versions of TypeScript. It was needed for many versions and I help a lot of packages to add the type definitions, including my own. Also for ESM, when I start converting my packages to dual modules a few months ago, I definitely notice they are needed, especially for subpath exports. e.g. the following didn't work when consuming as ESM when I tried it:
If it works without those fields, feel free to remove them. Less is more. 🍻 |
That's my guess. No real harm in having it there, if it makes some older versions of TypeScript work properly, then that's good enough reason to keep it. I am noticing that the same exact .d.ts files get duplicated using my hybrid setup, I wonder if there's a way to have one of them reference the other. Tricky when there's more than one module exported, though. |
There are two ways to do it:
Nowadays I use the second approach in my packages because I want to make sure everything are compiled correctly, including tests. Adding UPDATE: actually, don't do that. I'm working on a demo that you may need both: |
@isaacs 👆 pls ignore what I said about removing one set of declaration. |
Add types to the package.
TypeScript need this to read the type definition.
btw, the ESM one likely using
module: Node16
should be the correct value, instead ofESNext
.But that can be a different PR.