Created
April 18, 2016 19:22
-
-
Save jeffmo/b28cf7eb21dc783e6026a5617fe88075 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @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 { | |
return new HTMLCollection(/*...*/); | |
} | |
}; | |
let a: HTMLCollection<HTMLButtonElement> = getElem('a'); // Error | |
let b: HTMLCollection<HTMLAnchorElement> = getElem('a'); // No Error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> 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 | |
15: let a: HTMLCollection<HTMLButtonElement> = getElem('a'); // Error | |
^^^^^^^^^^^^^^^^^ HTMLButtonElement | |
main.js:15 | |
15: 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