Skip to content

Instantly share code, notes, and snippets.

@bodhi
Created April 23, 2017 14:16
Show Gist options
  • Save bodhi/4c0bd8b584cd606f7b3853db39edab5a to your computer and use it in GitHub Desktop.
Save bodhi/4c0bd8b584cd606f7b3853db39edab5a to your computer and use it in GitHub Desktop.
Define exact map using instance as reference.
/* @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