Skip to content

Instantly share code, notes, and snippets.

@kuy
Created January 9, 2017 07:07
Show Gist options
  • Select an option

  • Save kuy/817df8b2ffa2fc197bd849efd86dc14c to your computer and use it in GitHub Desktop.

Select an option

Save kuy/817df8b2ffa2fc197bd849efd86dc14c to your computer and use it in GitHub Desktop.
/* @flow */
type A = { a: string };
type B = { b: number };
type U = A | B;
type I = A & B;
// Union types
({ a: 'a' }: U);
({ b: 1 }: U);
({ a: 'a', b: 1 }: U);
({ a: 'a', b: 1, c: true }: U);
({ c: true }: U); // Error!
// Intersection types
({ a: 'a', b: 1 }: I);
({ a: 'a', b: 1, c: true }: I);
({ a: 'a' }: I); // Error!
({ b: 1 }: I); // Error!
({ c: true }: I); // Error!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment