« Prev 1 2 3 Next »

Announcing Flow Comments

February 20, 2015 by Gabe Levi

As of Flow 0.4.0, you can put your Flow-specific syntax in special comments. If you use these special comments then you do not need to transform away Flow-specific syntax before running your code. While we strongly recommend that you write your code without the special comments, this feature will help people who can’t fit a Flow-stripping transformation into their setup. This was one of our most requested features and hopefully it will enable even more people to use Flow!

This feature introduces 3 special comments: /*:, /*::, and /*flow-include. Flow will read the code inside these special comments and treat the code as if the special comment tokens didn’t exist. These special comments are valid JavaScript block comments, so your JavaScript engine will ignore the code inside the comments.


Announcing Typecasts

February 18, 2015 by Basil Hosmer

As of version 0.3.0, Flow supports typecast expression.

A typecast expression is a simple way to type-annotate any JavaScript expression. Here are some examples of typecasts:

(1 + 1 : number);
var a = { name: (null: ?string) };
([1, 'a', true]: Array<mixed>).map(fn);

For any JavaScript expression <expr> and any Flow type <type>, you can write

(<expr> : <type>)

Note: the parentheses are necessary.


Announcing Import Type

February 18, 2015 by Jeff Morrison

As of Flow 0.3.0, it’s now possible to import types from another module. So, for example, if you’re only importing a class for purposes of referencing it in a type annotation, you can now use the new import type syntax to do this.

Motivation#

Has this ever happened to you:

// @flow

// Post-transformation lint error: Unused variable 'URI'
import URI from "URI";

// But if you delete the require you get a Flow error:
// identifier URI - Unknown global name
module.exports = function(x: URI): URI {
  return x;
}

Now you have an out! To solve this problem (and with an eye toward a near future with ES6 module syntax), we’ve added the new import type syntax. With import type, you can convey what you really mean here — that you want to import the type of the class and not really the class itself.


« Prev 1 2 3 Next »