stylex icon indicating copy to clipboard operation
stylex copied to clipboard

chore: Add type references to package.json

Open kevintyj opened this issue 2 years ago • 3 comments

What changed / motivation ?

Adds "types" to all of the packages' package.json (if the build output includes a type declaration)

Linked PR/Issues

#46

Additional Context

TS Docs

Pre-flight Checklist

  • [x] I have read the contributing guidelines
  • [x] I have signed the contributing agreement
  • [ ] I have written unit tests where necessary (If it is a feature commit)
  • [x] Performed a self-review of my code
  • [x] Made sure PR title follows the conventional commit specification

kevintyj avatar Dec 06 '23 13:12 kevintyj

We use a different pattern to publish types where the type definition files shadow the source files. These files are regular Typescript code instead of declaration files.

AFAIK, this has been working correctly without the "types" field in package.json

I want to verify that this PR won't cause a regression before we can merge. Also, if a Typescript expert can chime in, that would be helpful.

nmn avatar Dec 06 '23 22:12 nmn

As long as the declaration file has the same name and path, as it does in this case, it will work without the "types" field.

See package.json "main" and "types"

If "types" and "typings" are not present or cannot be resolved, TypeScript will read the "main" field and perform extension substitution to find a declaration file.

joshuajaco avatar Dec 19 '23 23:12 joshuajaco

Thanks for the link @joshuajaco

When publishing a typed package to npm, it’s recommended to include a "types" field even if extension substitution or package.json "exports" make it unnecessary, because npm shows a TS icon on the package registry listing only if the package.json contains a "types" field.

This confirms that adding the types field to package.json is an improvement. Happy to merge once you rebase @kevintyj

nmn avatar Dec 19 '23 23:12 nmn

Thank you for your PR @kevintyj !

This change and more has been incorporated in a different PR that also adds ESM support, so I'm now closing this PR.

nmn avatar Jan 13 '24 02:01 nmn