The main point of creating Typescript is to give more robustness to complex systems. Javascript was created thinking for use in scripts very simple to automate some action on a page, not to make real software.
Although Typescript has script in the name it is not for that. The main point that differentiates a language from script for a language capable of handling more complex code bases is dynamic typing.
Typescript uses static typing in its code. So there are more rigid contracts, which is what gives robustness.
But TS was created to be compatible with JS, and in fact TS compiles to a JS target code (so in the execution the typing happens to be dynamic, but after compiled the robustness has already been guaranteed, only the performance will be dynamic language, which is worse, but it may not be so much because there are already some guarantees that Jitter can benefit in some points). You can mix TS and JS code, then TS was born very strong.
But JS codes don’t have manifest types so they don’t have these contracts. While it’s local, it doesn’t change anything for Typescript, but when it lacks typing in public Apis (parameters and return of methods for example) the TS compiler is rendered and can’t give the guarantees that it can normally give. Everything works, but it doesn’t get possible errors there, and tools may not help as much.
What then to do to put guys in something that didn’t have guys?
Well, in C/C++ these contracts have always been in separate files (in general the .h
of header). You first created them for all applications to use them because and only what the compiler needed to secure the contracts and then created the real codes that met those contracts.
In TS they did the opposite, they started creating these files after JS code already existed. Some people went to the main existing libraries for TS to see what the contracts were, as far as I could see (some libraries are very bad and the contract left very open, there is not much to do but to say explicitly that it is open even, just not to give error for nothing), and there they put in these files .d
the types of data that would be used in the existing Apis. So the TS compiler can use them to give the necessary guarantees. The .ts
final is to indicate clearly that this is from the TS, although it is related to a JS code, for the JS does not need this.
Any serious public library created today to web front which is not written in TS (and many more are), and which were then written in JS (comes out a new one per second, you know this :P :D) if it is serious the person already creates those files with the contracts to run well together with TS.
If you are making the code in TS even then these files are not necessary, at least if you are typing everything right as TS says. If you’re not typing then your code is half JS yet, there you need it, but it doesn’t make sense when you use TS.