Live data from Hacker News

Facebook Launches Flow, Static Type Checker for JavaScript

code.prod.facebook.com

21–30 of 282 posts

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#21
post #6

Is the type syntax friendly with CoffeeScript?

It looks like Flow should work to the extent that it can infer types from your CS output, but it will be tricky to embed explicit types into your CoffeeScript source.

You can probably hack it using the backtick operator though.

    `function foo(x: string, y: number): string {`
    x.length * y
    `}`

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#23
post #6

Is the type syntax friendly with CoffeeScript?

Looking at the source - it looks like it's not friendly with CoffeeScript in particular at the moment.

It'd be quite possible to add the ability to output these annotations to the CoffeeScript compiler itself though. Could be an interesting fork.

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#24
post #22

Question, in the doc it shows a code snipped that has the functioned defined as such "function foo(x: string)" What mechanism ensures this becomes valid javascript? does the code need to be compiled?

These should hopefully help you out.

http://flowtype.org/docs/existing.html#_ http://flowtype.org/docs/running.html#_

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#25
post #14

From my perspective, the static type checking is more or less the same as TypeScript's `--noImplicitAny` option as the first example on flowtype [1] shows, the same can be achieved with tsc --noImplicitAny hello.tsc which will result in hello.ts(2,14): error TS7006: Parameter 'x' implicitly has an 'any' type. I do not see much difference. [1]: http://flowtype.org

TS bolts on a straightforward nominative type system without type unions (or non-nullable types), so it can't handle a variable typed as `number | string`, it'll immediately drop down to `any`. That is, flow aims to remain useful in the face of more JS idioms. It won't make a difference between nullable and non-nullable either, so AFAIK

    function length(x) {
      return x.length;
    }

    length(null);
can never be a compile-time error in typescript.

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#26
post #22

Question, in the doc it shows a code snipped that has the functioned defined as such "function foo(x: string)" What mechanism ensures this becomes valid javascript? does the code need to be compiled?

It's ensured by a compilation step. From their website: "Typed Flow code easily transforms down to regular JavaScript"

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#27
post #22

Question, in the doc it shows a code snipped that has the functioned defined as such "function foo(x: string)" What mechanism ensures this becomes valid javascript? does the code need to be compiled?

This is _not_ valid JavaScript.

The code has a build step - yes. You will not be able to run this code without a step. It could be awesome if they allowed annotations in comments like other tools do - there is a GH issue on that and it looks like it should be possible https://github.com/facebook/flow/blob/master/src/typing/comm...

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#28
post #14

From my perspective, the static type checking is more or less the same as TypeScript's `--noImplicitAny` option as the first example on flowtype [1] shows, the same can be achieved with tsc --noImplicitAny hello.tsc which will result in hello.ts(2,14): error TS7006: Parameter 'x' implicitly has an 'any' type. I do not see much difference. [1]: http://flowtype.org

TS bolts on a straightforward nominative type system without type unions (or non-nullable types), so it can't handle a variable typed as `number | string`, it'll immediately drop down to `any`. That is, flow aims to remain useful in the face of more JS idioms. It won't make a difference between nullable and non-nullable either, so AFAIK function length(x) { return x.length; } length(null); can never be a compile-time…

Union types are present in the master branch of the TS compiler. The compiler also uses instanceof and typeof === ... to reduce the range of types inside a branch, similar to Flow.

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#29

Static analysis is definitely preferable to cross-compilation and this looks like a great tool. That said, the idea that static type checking makes developers more productive and prevents tons of errors is overstated imho. Type inference is supposed to make coding simpler and more productive (particularly in functional languages) - even C++11 has added it. I'm sure static type checking can benefit some organizations,…

This is a form of cross-compilation kind of like how TypeScript is cross compilation. It does require a build step to produce JavaScript - you will not be able to enjoy fiddles as easily and so on.

Then again their rationale is very clear and pretty good: You need builds if you're using Facebook's stack anyway (for JSX) so this should not interfere with your current build - which you have to do anyway.

Re: Facebook Launches Flow, Static Type Checker for JavaScript

#30
post #10

How this compares to TypeScript? At the quick glance I noted: - more powerful type system (union types, hurray) - support for JSX - no windows binaries - supports more of ES6 stuff - ...but has no support for modules yet - no generics (??) How about performance? and workflow? Didn't yet find this: does it use a normal "write then compile" model like TS or has something like Hack (if I'm not mistaken it has a daemon r…

>...but has no support for modules yet

I see some mentions of import in the tests and the grammar: https://github.com/facebook/flow/search?utf8=%E2%9C%93&q=imp...

Post reply on HN