Home > OS >  How to know that typescript type definitions in @types match the actual package
How to know that typescript type definitions in @types match the actual package

Time:11-27

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.

CodePudding user response:

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

CodePudding user response:

  1. If the package developers maintain the definitions themselves, there's no @types, d.tss are just building in package distro

  2. 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.

  3. 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

  • Related