Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is DefinitelyTyped appropriate for new TypeScript definitions?

According to https://blogs.msdn.microsoft.com/typescript/2016/06/15/the-future-of-declaration-files/:

DefinitelyTyped will still be the place to author new declaration files.

But it's unclear why we'd create new definitions at DefinitelyTyped as opposed to submitting them directly to NPM.

Being that DT is so large now, it seems counter productive to continue adding to that repo. What are the advantages of DT over publishing to NPM directly?

like image 463
Alex Dresko Avatar asked Jan 05 '23 07:01

Alex Dresko


2 Answers

The DefinitelyTyped repo is being treated as the endorsed community repository of type declarations for packages that don't provide their own.

Answering this question depends on what you mean when you say

submitting them directly to NPM.

If you mean including the .d.ts file with the package that the .d.ts file corresponds to that's encouraged. The moment package, for example, includes and maintains its own declaration file.

If you mean providing your own type only package then DefinitelyTyped is the better location for those files and will provide some advantages. By including your file in DefinitelyTyped it will

  • benefit from automated deploys to the @types namespace by the TS typings bot.
    • which will also yield predictable module resolution in the compiler.
  • be in the long established source for typings. You'll be where people are looking.
  • be more easily maintained by others.
    • the package will be easier to find
    • maintainers will use a workflow and format they're familiar with
like image 108
Paarth Avatar answered Jan 06 '23 20:01

Paarth


To add to Paarth's answer, being in DefinitelyTyped provides extra benefits you should consider:

  • Automatic version tags for older TypeScript language versions. If you ship your definition file in your own package, then you and your consumers have to agree on which version of TypeScript to use. If it's on DefinitelyTyped, as you update the definition file, the @types publisher will automatically tag the latest compatible release for older TS versions (e.g. people on TS 2.1 can npm install @types/[email protected] to get a 2.1-compatible version)
  • Free maintenance from the DefinitelyTyped maintainers. Often DT can find definition file bugs by writing new TSLint rules and applying them across the entire codebase
  • Better versioning - you can more easily provide side-by-side definitions for multiple versions of your library, and version these independently of the underlying library
like image 42
Ryan Cavanaugh Avatar answered Jan 06 '23 21:01

Ryan Cavanaugh