gpt4 book ai didi

typescript - 从 Flow 迁移到 Typescript : $Keys equivalent in TS?

转载 作者:行者123 更新时间:2023-12-05 09:14:13 24 4
gpt4 key购买 nike

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com