Hacker News new | ask | show | jobs
by abritinthebay 3896 days ago
In this case: because they want type enforcement. This removes a category of errors that - in a complex app - can be really annoying.

Better - it removes that ability for deliberate bad behavior by devs.

That said - I prefer JavaScript + Flow as thats a much more native solution which means you don't need to learn a pseudo language first.

1 comments

Typescript isn't exactly a pseudo-language. It looks just like JavaScript with Flow annotations. In fact, Typescript is intended to be JavaScript + Type Annotations, so it's just as "native" as JavaScript + Flow annotations, with the addition of some Babel-style ES6 transpiling as well. The only difference is the explicit build process versus running the transforms in browser, and I've seen projects use the Typescript compiler (itself written in JS) as their in-browser transpiler (SystemJS supports it as a first-class transpiler option alongside Babel and Traceur, even).
> It looks just like JavaScript with Flow annotations.

It looks close to that, yes. However Flow can be also implemented via comments to native JS so... TS can't do that.

In which case...

> it's just as "native" as JavaScript + Flow annotations

is wrong. TypeScript requires a transpilation step. Flow doesn't. It can do, but it's not required.

I may have been a little harsh with the "pseudo-language" but I'm not sure what else to call something that is designed to be transpiled into the right language. It's not higher-level, it's sort of... a companion language I guess.

You can write TS and put the type definitions into a separate file, so you don’t need a transpilation step. I am using this at the moment.