chore: Add type references to package.json
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
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
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.
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.
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
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.