DEV Community

Discussion on: TypeScript is a waste of time. Change my mind.

Collapse
 
danielearwicker profile image
Daniel Earwicker • Edited

“TypeScript is, by definition, longer than untyped JavaScript. As such, the development time is longer (assuming everything else is equal).”

This is only true if you believe that the effort required to create software consists mainly of mashing the keyboard, i.e. dev cost equals number of characters typed in by human fingers.

Obviously that’s not how it works. We spend more time thinking than entering code in an editor. Quality is way more of an issue than quantity. Therefore consider the possibility that by writing down some extra helpful information, development effort can fall.

Your other conclusions related to catching bugs. This is not the true value of static typing.

Think of a modern IDE as an intelligent assistant. It can assist you more if you let it know your intentions. Objects in some situation are meant to have a certain shape, so let your tooling know this fact! Declare what you mean to be true.

Meanwhile, other people reading your code can use the type declarations as documentation - but it’s way better than comments because it is definitely up-to-date, whereas comments usually aren’t.

TS infers the majority of type information (this is how VS Code is able to be so helpful with plain JS - it uses TS behind the scenes). But the remaining gaps where a declaration is needed are well worth filling in. Why? Because you’re stating facts that aren’t explicitly stated anywhere else. Without stating them, you’re leaving a vague puzzle for the next maintainer to figure out.

You have to write tests when using statically typed languages, of course - unit testing is commonplace in Java, C# etc. But writing tests is easier when your IDE does some of the donkey work for you. Types make your editor more helpful. Help your IDE to help you. And help the next maintainer too.

(Sidenote: you’re misinformed about C/C++ - they provide no runtime type safety; raw memory is interpreted according to the assumed type, and so a JPEG might try to be read as a string, or even executed as code).