DEV Community

Pragmatic Maciej
Pragmatic Maciej

Posted on

Advanced TypeScript series. Would you be interested?

Planning to run some advanced TS series on dev.to. Plan is to go through some really sofisticated examples of type system usage. Whould you be interested in such? And If so, what topic would be most interesting for you?

Top comments (16)

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.

Collapse
 
ac37s profile image
e1cb4 ac37s

There is package 'foo' which has '@types/foo' and the latter is used in project. The latter has some types/interfaces declared wrong (not fully typed or actually wrong). How to extend or rewrite those fishy places in local types not abandoning all other parts of original "@types..."?

Collapse
 
dansilcox profile image
Dan Silcox

Not sure how β€˜experimental’ the β€˜experimental decorators’ still are, thought about trying to implement a custom one the other day but kind of gave up! Maybe you could go into a bit more detail on how they work, when to/not to use them, etc?

Collapse
 
adam_cyclones profile image
Adam Crockett πŸŒ€ • Edited

Decorators are still in draft and have been for ages. github.com/tc39/proposal-decorators

But as this is compiled sec for a language that never actually runs, it's safe to use. Same for babel.

Collapse
 
shofol profile image
Anower Jahan Shofol

OOP implementation by typescript.

Collapse
 
nombrekeff profile image
Keff

Generics would be a nice thing to cover :)

Collapse
 
emaraschio profile image
Ezequiel Maraschio

Please write about generics πŸ€“

Collapse
 
seanmclem profile image
Seanmclem

I think advanced typescript should include some intermediate OOP, since that's often not solidified for JS developers

Collapse
 
khrome83 profile image
Zane Milakovic

Please do this! I will try and think of some other things people didn’t already say. But yes, this would be great!

Collapse
 
adam_cyclones profile image
Adam Crockett πŸŒ€

Enums please (I know what they are in other languages) how do they or compile / or they dont?