DEV Community

Cover image for Consider Using TypeScript

Consider Using TypeScript

Nick Taylor on October 08, 2017

I'm not going to be one of those that tells you have to use TypeScript (or Flow for that matter). I'm also not going to go into the whole TS vs. Fl...
Collapse
 
andrewbaisden profile image
Andrew Baisden

Static type checking is so useful.

Collapse
 
lexlohr profile image
Alex Lohr

Actually, I find the main case for type systems in JS (no matter if flow or typescript) to be in-code documentation, with the added advantage that it doesn't inflate your code as much as JSdoc or similar syntax extensions do, so it doesn't break my reading flow.

For teams of more than 2-3 persons, I would definitely recommend using a type system. If you have an existing code base, flow with its powerful type inference and the ability to add type descriptions in comments (so you don't even need to change your build chain) will be the better choice in my opinion. If you have a new project, either choice is fine.

Collapse
 
nickytonline profile image
Nick Taylor • Edited

Thanks for the feedback.

The in-code documentation is great. I mention it indirectly, i.e. Intellisense. I might update the article to mention that point more explicitly.

Switching build chains is not really pertinent to this article as the premise is to use TypeScript. I understand though that the Babel ecosystem is what most are used to, so transitioning to the TS build chain could be a pain to some.

Collapse
 
lexlohr profile image
Alex Lohr

Thanks for your answer. About the in-code documentation: even if you don't use Intellisense, it helps: you can get an idea about how to use a library much faster with type annotations.

As about the transitioning Even if the legacy project doesn't use babel, but plain ES5, maybe with jQuery, you can still add some type comments like /* : string[] */ (or even let flow's type inference do its magic; it will usually cover ~50% of your project without you doing anything) and enjoy at least a bit of type safety without changing anything else.

Collapse
 
nickytonline profile image
Nick Taylor

This video that just came out very recently explains a lot of the benefits of TypeScript, #FiveThings that TypeScript Can Do for You. Super funny and worth a watch.

Collapse
 
bgadrian profile image
Adrian B.G.

Order into Chaos, light in the dark, types in anarchy, may the TypeScript God conquer more & more projects.

Collapse
 
rattanakchea profile image
Rattanak Chea

I have been using Typescript recently. It has helped catching syntax problems and forced to change the way I think about the paradigm in OOP.

Collapse
 
nickytonline profile image
Nick Taylor

Another project that migrated to TypeScript

Collapse
 
nickytonline profile image
Nick Taylor

Looks like the next major version of Vue will be written in TypeScript. 🔥