Created
April 23, 2017 14:16
-
-
Save bodhi/4c0bd8b584cd606f7b3853db39edab5a to your computer and use it in GitHub Desktop.
Define exact map using instance as reference.
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 */ | |
const messages = { | |
"a": "A", | |
"b": "B", | |
} | |
type Locale_ = typeof messages | |
type Key = $Keys<Locale_> | |
type Locale = { | |
...Locale_, | |
...{ [ Key ]: string } | |
} | |
const de: Locale = { | |
"a": "A", | |
// "b": "B", // Error: property `b`. Property not found in Locale object literal | |
} | |
const fr: Locale = { | |
"a": "A", | |
"b": "B", | |
"c": "C" // Error: property `c`. Property not found in...{ [ Key ]: string } object literal | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment