Created
August 2, 2018 08:59
-
-
Save karlhorky/be0331af480f4cdaef68cf79768adf5c to your computer and use it in GitHub Desktop.
Flow Type: Literal Type Generic Type
This file contains 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 | |
// Originally from https://github.com/facebook/flow/issues/2639#issuecomment-409803679 | |
const foo = 'FOO'; | |
function literal(type) { | |
return { [type]: type }; | |
} | |
type LiteralType<T> = $Keys<$Call<typeof literal, T>>; | |
('FOO': LiteralType<typeof foo>); // No errors | |
('BAR': LiteralType<typeof foo>); // Error: property `BAR`. Property not found in object literal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment