Skip to content

Instantly share code, notes, and snippets.

@vilterp
Last active May 27, 2016 00:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vilterp/3a344a27d2e2f55d9b2679900a70c60d to your computer and use it in GitHub Desktop.
Save vilterp/3a344a27d2e2f55d9b2679900a70c60d to your computer and use it in GitHub Desktop.
peterv@vilterp-mbp:flow-test$ flow version
Flow, a static type checker for JavaScript, version 0.25.0
peterv@vilterp-mbp:flow-test$ flow
flowTest.js:7
7: var y: Foo = {...x, a: 5};
^^^^^^^^^^^^ object literal. This type is incompatible with
7: var y: Foo = {...x, a: 5};
^^^ union: object type(s)
Member 1:
3: type Foo = { type: 'foo', a: number, b: number } | { type: 'bar', c: string };
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ object type
Error:
3: type Foo = { type: 'foo', a: number, b: number } | { type: 'bar', c: string };
^^^^^ string literal `bar`. Expected string literal `foo`, got `bar` instead
3: type Foo = { type: 'foo', a: number, b: number } | { type: 'bar', c: string };
^^^^^ string literal `foo`
Member 2:
3: type Foo = { type: 'foo', a: number, b: number } | { type: 'bar', c: string };
^^^^^^^^^^^^^^^^^^^^^^^^^^ object type
Error:
3: type Foo = { type: 'foo', a: number, b: number } | { type: 'bar', c: string };
^^^^^ string literal `foo`. Expected string literal `bar`, got `foo` instead
3: type Foo = { type: 'foo', a: number, b: number } | { type: 'bar', c: string };
^^^^^ string literal `bar`
Found 1 error
peterv@vilterp-mbp:flow-test$
/* @flow */
type Foo = { type: 'foo', a: number, b: number } | { type: 'bar', c: string };
var x: Foo = { type: 'foo', a: 1, b: 2 };
var y: Foo = {...x, a: 5}; // this is a valid `Foo`, but Flow says it's not
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment