Skip to content

Instantly share code, notes, and snippets.

@asolove
Created April 20, 2016 22:51
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 asolove/cdd3a0e62fe2f757179f8bac8e01e349 to your computer and use it in GitHub Desktop.
Save asolove/cdd3a0e62fe2f757179f8bac8e01e349 to your computer and use it in GitHub Desktop.
Subtyping polymorphism!
// @flow
type Foo<A> = { n: number, extra: A };
type Foo2 = Foo<{s: string}>;
type Bar<A> = { foo: Foo<A> };
type Bar2 = { foo: Foo2 };
function getBarN(bar: Bar){ return bar.foo.n }
function getBarS(bar: Bar2){ return bar.foo.extra.s }
let bar2: Bar2 = { foo: { n: 2, extra: {s: ""} }};
getBarN(bar2);
getBarS(bar2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment