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

1

8

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?

Aerification answered 14/8, 2016 at 13:53 Comment(1)
I just manually manage my typings locally; works wonder. I occasionaly copy them from definatelyTyped if they're of good enough quality and up to date, which is not that often.Intension
D
8

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

Decoration answered 14/8, 2016 at 14:24 Comment(1)
Thanks @drinchev, looks accurate - something worth pointing out is that Typings was and is an exercise to show how dependencies should be managed using TypeScript (previously it wasn't possible with DefinitelyTyped + TSD, and as a module author myself this was unacceptable). TypeScript now understands this and has worked to help incorporate a proposal into core for 2.0.Peggie

© 2022 - 2024 — McMap. All rights reserved.