1
从流程的文档,我们有这样的:
// @flow
const countries = {
US: "United States",
IT: "Italy",
FR: "France"
};
type Country = $Keys<typeof countries>;
const italy: Country = 'IT';
const nope: Country = 'nope'; // 'nope' is not a Country
但是我想要做的
type CountryValue = $Values<typeof countries>
const italy: CountryValue = 'Italy'; // yes
这可能吗?
Ah darn,谢谢你,看来我必须定义'type FullNames'枚举,所以不妨使用这个吧? – Blagoh
是的,看起来它不会从对象字面值中推断枚举类型。哪种类型是有意义的,因为大多数类型都有对象字面值,所以您不想将其限制为初始值。 – Adam
非常感谢您的帮助,我已经接受了这一点,因为至少它的工作原理和传达的信息是,它应该是该对象中的一个值,并确保该对象中的值来自给定的:) – Blagoh