Skip to content

Instantly share code, notes, and snippets.

let foo: ?number;
function bar() {
if (foo == null) {
return;
}
setTimeout(() => {
// I refined above, so this should work right?
// (hint: wrong. If `foo` were const, then it would be a correct/more intuitive assumption)
var a: mixed = foo();
var b: number;
b = a; // error! `a` might not be a number... Could be anything!
if (typeof a === 'number')) {
b = a; // This is safe -- no error
} else {
throw new Error('Unexpected type of `a`!');
}
// @flow
const a: number = 'asdf';
const b: string = 2;

###master (next release)

###v0.23.1

  • Fixed parsing of JSON files with duplicate object keys

###v0.23.0

Likely to cause new Flow errors:

  • When you refine a mixed variable with typeof myVar === 'object', we used to refine the type of myVar to null | Object. Now it is refined to null | {[key: string]: mixed}. This means myVar.prop has the type mixed rather than any.
// @flow
var a = 42;
export default a;
// @flow
declare function getElem(name: 'a'): HTMLCollection<HTMLAnchorElement>;
declare function getElem(name: 'button'): HTMLCollection<HTMLButtonElement>;
function getElem(name) {
if (name === 'a') {
return new HTMLCollection(/*...*/);
} else {
// @flow
declare function getElem(name: 'a'): HTMLCollection<HTMLAnchorElement>;
declare function getElem(name: 'button'): HTMLCollection<HTMLButtonElement>;
function getElem(name) { return (42: any); };
let a: HTMLCollection<HTMLButtonElement> = getElem('a'); // Error
let b: HTMLCollection<HTMLAnchorElement> = getElem('a'); // No Error
// @flow
import EventEmitter from 'eventemitter3';
class foo extends EventEmitter {
}
const x = new foo();
x.bar(); //Should error as bar is not a method of foo. - does not. Changing
@jeffmo
jeffmo / -
Created February 12, 2016 18:57
{"passed":true,"errors":[],"version":"1d57ebd3661650edcecc6a3924d3353c70407966 Feb 1 2016 18:11:05"}
@jeffmo
jeffmo / _code.js
Last active January 21, 2016 19:12
function foo({bar: {baz}}: SomeType) {}