DEV Community

Discussion on: Advanced TypeScript series. Would you be interested?

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt • Edited
Collapse
 
adam_cyclones profile image
Adam Crockett 🌀 • Edited

Honestly you don't have to write a .d.ts these days, tsconfig can let you generate one with one of its many options (to drunk to look it up sorry)

Edit: for js authored libs you can use Microsoft's cli tool as seen bellow.

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt • Edited

This is actually not true. There are too many pure JavaScript projects with or without JSDoc (and sometimes TypeScript IntelliSense just doesn't read JSDoc...) That's why github.com/DefinitelyTyped/Definit... exists, which are actually hand-written *.d.ts's.

(Though, I know it is possible to generate *.d.ts from JSDoc. I do that sometimes.)

You can also add *.d.ts to a pure JavaScript project of someone else, without submitting to DefinitelyTyped. Even if they don't merge the PR, npm install *.git from GitHub is definitely an option.

Thread Thread
 
adam_cyclones profile image
Adam Crockett 🌀

Ah ... Of course, I wasn't thinking about this context where a library was not originally authored in Typescript (but I was drunk so you can let me off). I'm sure there is tooling to introspect JavaScript libs and generate .d.ts files anyway. When there's a will there's a way.

Thread Thread
 
macsikora profile image
Pragmatic Maciej
Thread Thread
 
adam_cyclones profile image
Adam Crockett 🌀

Thank you Maciej and thank you Microsoft.

So you see a definition file is not desirable to hand write because, it's bad enough maintaing code that actually do something, can you imagine refactoring this every time you make a change as well, people would rage quit typescript. I used to do it by hand then decide I cba. But there we go, you can and should generate as much as possible.

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

tsconfig is like glasses, stick to the default you will know what to change / lookup when things are not working the way you want.