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

Check packages for index.d.ts without types or typings field in package.json #64

Closed
karlhorky opened this issue Jan 27, 2021 · 10 comments
Closed

Comments

@karlhorky
Copy link
Contributor

#24 implemented checks for internal types in packages, but it seems like it didn't address the case of a package with an index.d.ts but no types / typings field in package.json.

This is apparently allowed, according to TypeScript docs (and also used in the wild):

https://twitter.com/sindresorhus/status/1342368373296881664

@jeffijoe
Copy link
Owner

Is that file included in the files array of the package?

@karlhorky
Copy link
Contributor Author

karlhorky commented Jan 28, 2021

Yep, it is: https://unpkg.com/browse/[email protected]/package.json

Is the files key also considered?

I guess this would work in most cases! Wonder if there are any cases in which this would fail (eg. no files key, or a files key with a wildcard, etc)

@jeffijoe
Copy link
Owner

I suppose a check for any *.d.ts will do in the files array.

@karlhorky
Copy link
Contributor Author

Could you just check for the existence of index.d.ts on disk (in node_modules)? Or is there an issue with this?

@jeffijoe
Copy link
Owner

I would prefer not having to check node modules, currently everything works off of the package defs.

@jeffijoe
Copy link
Owner

Just so I understand the issue, you want the presence of index.d.ts in the files array to prevent the lookup of a @types/ variant, similar to the presence of a typings field?

@karlhorky
Copy link
Contributor Author

Yep, that seems like an accurate description 👍

@jeffijoe
Copy link
Owner

It seems even the NPM API doesn't return the files array either. So I think this is better solved by making packages specify their typings correctly in the package using types or typings.

@karlhorky
Copy link
Contributor Author

Files on disk would be an alternative.

Also, there are other ways of doing it - eg. relying on a single request (either GET or HEAD) to the popular, performant CDN UNPKG:

I think it's a popular enough pattern in npm package publishing to put in some work to try to support it.

@jeffijoe
Copy link
Owner

jeffijoe commented May 1, 2023

Files on disk would not be deterministic, as there would be a difference between running typesync before or after an npm install

Using unpkg is an idea, but considering how I just got burned from using 2 different sources, I would rather stick to what npm returns.

ky now includes the types field, by the way.

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