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

ESM imports TypeScript types #58

Open
pmer opened this issue Jul 18, 2022 · 5 comments
Open

ESM imports TypeScript types #58

pmer opened this issue Jul 18, 2022 · 5 comments

Comments

@pmer
Copy link

pmer commented Jul 18, 2022

If I understand correctly, the TypeScript types are for the CommonJS version of the code. When using "module": "ES2022" in tsconfig.json with allowSyntheticDefaultImports: false, importing getopts fails unless the type definitions are changed from:

export = getopts

to

export default getopts

It might be possible to resolve this by providing different type definitions for CommonJS and ESM (different on only this one line) and using an extension to package.json that TypeScript 4.7 added (link) that lets TypeScript pick between type definition files based on the project's module type.

Alternatively, enabling allowSyntheticDefaultImports for the project seems to fix it, too.

@jorgebucaran
Copy link
Owner

What about updating the types to support only ES modules? 🤔

@pmer
Copy link
Author

pmer commented Jul 21, 2022

Hmm, interesting idea. Personally, I do not feel that I know enough to opine very strongly on this type of thing. Wonder if it would be possible to find open source users of getopts on NPM, then try building them with and without such a change to see if it would cause any disturbances, and by how much. But this is just because I am not an expert in this area!

@pmer
Copy link
Author

pmer commented Jul 23, 2022

Looks like Chalk has done this in v5 https://github.com/chalk/chalk/releases

@jorgebucaran
Copy link
Owner

@pmer Works for me! Do you want to send me a patch with the change? 💯

@pmer
Copy link
Author

pmer commented Jul 26, 2022

If I can find the time to test it, would love to! 😀

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

No branches or pull requests

2 participants