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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

add types to package.json #253

Closed
wants to merge 1 commit into from
Closed

add types to package.json #253

wants to merge 1 commit into from

Conversation

mmkal
Copy link

@mmkal mmkal commented Jan 31, 2024

I'm surprised this is needed, but it seems to be. Types are not being inferred with just the exports.types field. This seems to be the case on npmjs.com, in VSCode, and via the typescript compiler.

Adding types seems to fix.

A few ways to see it's not right at the moment:

Demo in typescript playground (note that if you reach into the package via import meow from 'meow/build/index.js', you do get the correct types 馃し.

Are The Types Wrong result

DT icon on npmjs.com:

image

I'm surprised this is needed, but it seems to be. Types are not being inferred with just the `exports.types` field. This seems to be the case on npmjs.com, in VSCode, and via the typescript compiler.
@sindresorhus
Copy link
Owner

The current config is correct.


This seems to be the case on npmjs.com, in VSCode, and via the typescript compiler.

Then you should open an issue in those places. Usually, this issue is caused by incorrect tsconfig (not having module and moduleResolution set to node16.

@mmkal
Copy link
Author

mmkal commented Feb 3, 2024

I'll see if there's an existing issue in typescript. In the meantime, I came across this on np, working on sindresorhus/np#730, which is written in plain js. So no tsconfig at all. The inferred type for meow in vscode is any. Would you suggest jsconfig.json there?

@sindresorhus
Copy link
Owner

So no tsconfig at all. The inferred type for meow in vscode is any. Would you suggest jsconfig.json there?

No, I would argue this is a VSCode/TS issue for when using comment annotations. It should respect that meow is a ESM package with an exports field and use node16 resolution.

@mmkal
Copy link
Author

mmkal commented Feb 3, 2024

You're right. Even so, adding a jsconfig there/changing package.json here are much quicker quality-of-life improvements. They can be done today.

@sindresorhus
Copy link
Owner

Even so, adding a jsconfig there/changing package.json here are much quicker quality-of-life improvements. They can be done today.

I'm willing to add a jsconfig to np if you open the mentioned issues. I want to make sure the jsconfig can be removed eventually.

@mmkal
Copy link
Author

mmkal commented Feb 3, 2024

Will do. Combing through existing issues first - "exports" and "types" don't narrow down typescript's 5k open issues much!

Worth noting, I'm fine to do it but I still think this temporary solution is better than jsconfig.json. It's a one line fix that solves for all js projects that use meow. A jsconfig there is a new file that only solves for one repo.

@sindresorhus
Copy link
Owner

sindresorhus commented Feb 3, 2024

Worth noting, I'm fine to do it but I still think this temporary solution is better than jsconfig.json. It's a one line fix that solves for all js projects that use meow. A jsconfig there is a new file that only solves for one repo.

Yes, but it's unknown whether that could potentially cause problems with other tools. And if everyone simply works around TS bugs, the TS team have no incentive to fix things.

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.

None yet

2 participants