DEV Community

Discussion on: Is 2019 the year of TypeScript?

Collapse
 
seangwright profile image
Sean G. Wright • Edited

I think one of the wonderful things about Typescript is that it's an opt-in type system.

You can take the following JavaScript file (app.js):

const names = ['lawrence', 'kim', 'koala'];

const shortNames = names.filter(n => n.length <= 4);

And copy it into a Typescript file (app.ts):

const names = ['lawrence', 'kim', 'koala'];

const shortNames = names.filter(n => n.length <= 4);

And then compiled it with the Typescript compiler:

tsc app.ts

No changes were need to my JavaScript!

If I wanted to I could add just 1 type:

const names = ['lawrence', 'kim', 'koala'];

const shortNames: string[] = names.filter(n => n.length <= 4);

And everything still works!


Sure, Typescript code that you might see in an Angular application can have types everywhere and a bunch of strict compiler flags - but this is one side of the spectrum.

Typescript is happy and helpful anywhere along that spectrum.

Use :any (or don't add an annotation at all - it's the same thing), leave the compiler options loose, and ease yourself into it.

Then as the project grows in complexity, start flipping on compiler flags, add more types and see where your expectations of your code don't match reality.


If you just prefer no type information in your code, cool! Don't use Typescript :)

(JavaScript still has types, it's just weakly typed and doesn't require you to specify them)

But it's not an all or nothing thing - approach Typescript on your own terms and I think you'll find it enjoyable and interesting.