Skip to content

Instantly share code, notes, and snippets.

###v0.18.0

Likely to cause new Flow errors:

  • Flow is now stricter (and more consistent) about how null works when used as an initialization value for object properties that are mutated later. So let o = {prop: null}; o.prop = 42; is now an error and requires that null be annotated in the object initializer: let o = {prop: (null: ?number};.
  • The return type of RegExp.prototype.match() is now properly annotated to return a nullable. As a result, 0.18 may uncover places where .match() wasn't properly being guarded for a null return value.

New Features:

  • We now take advantage of the guarantee that const variables are read-only when doing refinements. This means that refining const variables now has far fewer caveats than refining lets or vars!
/* @flow */
var otherObj = {
nullableProp: "asdf",
prop: 42,
};
var a = {nullableProp: null, ...otherObj};
/* @flow */
var otherObj = {
nullableProp: ("asdf": ?string),
prop: 42,
};
var a = {nullableProp: null, ...otherObj};
[libs]
types
[libs]
types
// @flow
type Action =
{type: 'b', prop1: string}
| {type: 'c', prop2: string};
function onAction(action: Action): void {
switch (action.type) {
case 'b':
// If you comment the following conditional return, Flow stops erroring on
/* @flow */
type Float = number;
type Interpolation<a> = (_:a, _:a, _:Float) => a;
const float: Interpolation<Float> = (from, to, progress) => from + (to - from) * progress;
const a: number = float(42, 42, 42);
const b: string = float('asdf', 'asdf', 42);
/* @flow */
type Float = number;
type Interpolation<a> = (_:a, _:a, _:Float) => a;
const float: Interpolation<Float> = (from, to, progress) => from + (to - from) * progress;
const a: number = float(42, 42, 42);
const b: string = float('asdf', 'asdf', 42);
/* @flow */
var a: {[_:string]:number, b: number} = {
a: 1,
b: 2,
}
var b = {c: 'asdf'};
/* @flow */
const run = (task:?Function) => {
if (task != null) {
const safeTask = task;
const run = () => {
return safeTask()
}
run()