Flow 有方便的 $Keys
实用函数,可以从对象中提取键并创建字符串文字的联合。所以你可以这样做:
const foo = {
input: Input,
button: Button,
select: Select
}
type FormType = $Keys<typeof foo> // FormType now is: 'input' | 'button' | 'select'
Typescript 是否具有等效功能?我知道keyof
但这只能获取接口(interface)
的键,而Flow可以获取对象的键。
最佳答案
等价于keyof
类型的运算符:
type FormType = keyof typeof foo
关于typescript - 从 Flow 迁移到 Typescript : $Keys equivalent in TS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54595514/
相关文章:
python - 如何将 Base64 图像字符串从 Flask Python 代码传递到 HTML
python - 如何展平嵌套模型? (keras 函数式 API)
python-3.x - 如何从 gensim 模块导入 WordEmbeddingSimilari
amazon-web-services - 是否可以在控制台中编辑 AWS Lambda 层代码?
kubernetes - 在 Kubernetes (GKE) 中的一个节点上组合多个本地 SSD
reactjs - React.HTMLProps
angular - 如何使用 typescript 修复 Angular 5 中的 ‘debounc