DEV Community

Discussion on: TypeScript and why you should type your JS project

Collapse
 
matjones profile image
Mat Jones

TypeScript is like JavaScript but with no surprises.

Sorry but this is just utterly false for so many reasons.

Collapse
 
johnkazer profile image
John Kazer

Could you list a few?

Collapse
 
matjones profile image
Mat Jones

Incorrect types for open source packages, happens quite often

If you’re targeting the browser... Internet Explorer

Generics not working the way you expect them to in certain scenarios

There’s lots. It’s also just a superset of JavaScript, so any surprise JavaScript can produce, typescript can also product.

Thread Thread
 
migueldevelopez profile image
MiguelDevelopez

Thanks for sharing these points, Mat!
I'll investigate the cons of using TS 🤔

Thread Thread
 
matjones profile image
Mat Jones

Don’t get me wrong, TS is a VAST improvement over JS, but it does have its own set of “gotchas”

Thread Thread
 
migueldevelopez profile image
MiguelDevelopez

To be honest, I don't use TypeScript yet, I just found it very interesting and loved by the community so... for that reasons I decided to write this, but I have in mind to start a little project to check his good points (and the bad ones too) 👏

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

That's true. But then TypeScript is getting better.

The latest change is ability to make array and record indexing return undefined. (by settings in tsconfig.)

But yes, I will never trust TypeScript to be truly safe, nor truly strongly typed.

Collapse
 
matjones profile image
Mat Jones

Yeah, don’t get me wrong, TS is still a VAST improvement over JS.

Collapse
 
migueldevelopez profile image
MiguelDevelopez

and if you combine types and tests, will make the code reliable?

Thread Thread
 
matjones profile image
Mat Jones

If you have reliable enough tests, sure. And to be clear, I still think TS is a huge improvement over JS.

Thread Thread
 
johnkazer profile image
John Kazer

Having types of some sort helps me greatly in just writing functions, because it makes it much easier to remember just what data I'm messing around with. But I do tend to a functional/data-first style. So it reduces cognitive load way before you get to using tests/compiler to check things. And so, in fact, if your types are wrong your function/data manipulation will go wrong when you write it and a compiler/running tests are secondary things.