流程有得心应手$Keys
效用函数,可以从一个对象中提取键,并创建字符串文字的联合。所以,你可以这样做:
const foo = {
input: Input,
button: Button,
select: Select
}
type FormType = $Keys<typeof foo> // FormType now is: 'input' | 'button' | 'select'
是否打字稿具有同等功能?我知道keyof
,但只得到一个interface
的钥匙,当流量可以得到一个对象的键。
相当于是keyof
型操作符:
type FormType = keyof typeof foo