Reputation: 24953
Why do Typescript projects include .d.ts definitions... seems counter productive?
If a library is already developed in TypeScript (like Angular2 let's say), and the TS transpiler can use the source .ts files for intellisence, why do I keep seeing in TS projects .d.ts file being included?
Now sure you can easily generate .d.ts definition via the tsd executable, but I can't see the logic.
regards,
Sean
Upvotes: 2
Views: 351
Reputation: 84744
It comes down to distribution. Referencing a project via npm/bower provides a "main" file that is javascript, not typescript. As such, it makes most sense for the compilation output of a Typescript project to be:
a) The transpiled javascript file, possibly minified
b) A .d.ts file describing the type annotations (kind of like a header file in C)
It wouldn't make much sense to distribute in typescript since it either would prevent javascript projects from using it, or would necessitate a separate typescript version of the npm package.
Upvotes: 5