Reputation: 407
I have been using typescript for a little while in node.js projects. I understand that for many npm packages there is separate @types package for typescript type definitions.
My question is: how can I know that the @types package is up to date with the latest version of the actual package when they are maintained separately?
For example there is npm package better-sqlite3 with no typescript definitions and then a separate type definition package @types/better-sqlite3. How user of the package can know that types match the current version of the package?
In this answer here it is said that "TypeScript types for JS packages is best effort and depends on Community interest in the package". This sounds a bit scary.
Upvotes: 1
Views: 1569
Reputation: 7194
The types package shouldn't be maintained separately. The author of the package should be listing the corresponding types package as a dependency
which means the correct version of the typing should come along when you install the top-level package.
REF: https://github.com/Microsoft/types-publisher/issues/81
Edit: As pointed out in the comments by @Gwydion, there are some packages that are community maintained outside of the originating package. A good example is:
https://www.npmjs.com/package/better-sqlite3
It would seem likely the following package is the correct types package:
https://www.npmjs.com/package/@types/better-sqlite3
But, it's not necessarily obvious either. It would be nice to have to signal to verify that this is the correct package.
Here is what I did:
I visited the originating npm package page, taking note of the repository URL which is: https://github.com/WiseLibs/better-sqlite3
I visited the repository URL of the type package, which is: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/better-sqlite3 (this URL was listed on the type package's npm page under Details)
Open the index.d.ts
file located there. At the top it lists: Project: https://github.com/JoshuaWise/better-sqlite3
.
NOTE: https://github.com/JoshuaWise/better-sqlite3 redirects to https://github.com/WiseLibs/better-sqlite3 which matches what we found in #1 above.
Upvotes: 1
Reputation: 10841
If the package developers maintain the definitions themselves, there's no @types
, d.ts
s are just building in package distro
If there's @types
, you may check the last update date of both packages (@types
have Last updated
in readme), the @types
probably was correct at the time when it was last updated.
If the @types
is outdated, you may update if yourself and even publish on @types
, that's what "TypeScript types for JS packages is best effort and depends on Community interest in the package" means
Upvotes: 1