There are many resources explaining a declaration file (d.ts) is useful for either:
What confuses me is that many projects like material-ui are using d.ts files to simply store types and have them consumed in their own code.
At this point I start questioning, what's the point in having types.ts
files where we have to export / import types and interfaces to consume them, when we could have types.d.ts
files and simply consume its interfaces / types without the need for exporting / importing? What are the pros and cons of using one over the other?
In most cases you should just write typescript files, and let the compiler generate your .d.ts
files for you. This is almost always the right choice, except:
.d.ts
files can help you override those types.I imagine Material UI in group 1 for this. Deno is in group 3.
tl;dr: stick to writing typescript. Writing javascript and separate type files is extremely unergonomic and you lose a ton of the benefits of typescript.