yon*_*nmn 5 javascript flowtype
流量keys,让你说的像:
const countries = {
US: "United States",
IT: "Italy",
FR: "France"
};
type Country = $Keys<typeof countries>;
const italy: Country = 'IT';
Run Code Online (Sandbox Code Playgroud)
但如果我想有一个values的Country,我无法找到正确的方法.
我想要的东西:
function getCountryPopulation(country: $Values<typeof countries>){
...
}
getCountryPopulation(countries.US) //fine
getCountryPopulation("United States") //fine
getCountryPopulation("Canada") //fail
Run Code Online (Sandbox Code Playgroud)
$Values 降落在`@0.53.1.
用法,每vkurchatkin:
const MyEnum = {
foo: 'foo',
bar: 'bar'
};
type MyEnumT = $Values<typeof MyEnum>;
('baz': MyEnumT); // No error
Run Code Online (Sandbox Code Playgroud)
有关更多上下文:https: //github.com/facebook/flow/issues/961