Skip to content

Instantly share code, notes, and snippets.

@jeffmo
Created April 18, 2016 19:21
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 jeffmo/0c683cb38cd908251bc49be18d9a05c3 to your computer and use it in GitHub Desktop.
Save jeffmo/0c683cb38cd908251bc49be18d9a05c3 to your computer and use it in GitHub Desktop.
// @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 version
Flow, a static type checker for JavaScript, version 0.23.0
> flow check
main.js:4
4: declare function getElem(name: 'a'): HTMLCollection<HTMLAnchorElement>;
^^^^^^^^^^^^^^^^^ HTMLAnchorElement. This type is incompatible with
9: let a: HTMLCollection<HTMLButtonElement> = getElem('a'); // Error
^^^^^^^^^^^^^^^^^ HTMLButtonElement
main.js:9
9: let a: HTMLCollection<HTMLButtonElement> = getElem('a'); // Error
^^^^^^^^^^^^^^^^^ HTMLButtonElement. This type is incompatible with
4: declare function getElem(name: 'a'): HTMLCollection<HTMLAnchorElement>;
^^^^^^^^^^^^^^^^^ HTMLAnchorElement
Found 2 errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment