Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best solution for type definition management system(like tsd) for Typescript?

When it comes to use Typescript, we need to consider how to resolve type definition files (*.d.ts).

As long as I know, there are several systems for managing typescript definition system as below.

  • tsd
  • typings
  • @types

I guess tsd is the oldest one and that is origin. But, why typingsneeded to be born? I guess making definition file for typings is a little bit complex.

And what is @types actually?

Then, what is the best solution around this?

like image 541
kyasbal Avatar asked Aug 14 '16 13:08

kyasbal


1 Answers

The story behind the typings management ecosystem around TypeScript is very big.

First there was ( still is ) a monolith repository called DefinitelyTyped which was used as a hub to all developers that wanted to contribute their typings for different libraries.

Because of this repository a typings manager called tsd which directly takes the typings from that repository and saves them locally in your project.

Meanwhile the DT repo exceeded it's scaling abilities and had to be restructured. The discussion went further in the way how a d.ts. file should look like, so at one point there was a need for another way of including the typings in your project. Another problem was the versioning of libraries and TypeScript compiler itself.

Then at one point Blake Embrey created a new typings manager called typings which had a support for DefinitelyTyped and the new proposed way of structuring a d.ts. The new structure allowed for two types of modules - globals ( most of the DefinitelyTyped ones ) and modules that are supposed to be encapsulated.

Later TypeScript 2.0 Beta was announced by Microsoft. The team behind TypeScript realized the need of a different way in handling typing files. What they did was a @types npm scope, which they announced will be the new way of handling typings. At this point @types only works with TypeScript 2.0.

Declaration files (.d.ts files) are a fundamental part of using existing JavaScript libraries in TypeScript, but getting them has always been a place where we’ve known there was room for improvement. As we get closer to TypeScript 2.0, we’re very excited to show off a sneak peak of our plan to simplify things. Getting type declarations in TypeScript 2.0 will require no tools apart from npm.

So to the answer of your question :

If you use TypeScript below v2.0 use typings, but if you use 2.0 use @types

like image 101
drinchev Avatar answered Sep 30 '22 20:09

drinchev