从 Flow 迁移到 Typescript:TS 中的 $Keys 等效?

Squ*_*ler 2 typescript flowtype

Flow 具有方便的$Keys实用功能,可以从对象中提取键并创建字符串文字的联合。所以你可以这样做:

const foo = {
   input: Input,
   button: Button,
   select: Select
}

type FormType = $Keys<typeof foo>      // FormType now is: 'input' | 'button' | 'select'
Run Code Online (Sandbox Code Playgroud)

Typescript 是否具有等效功能?我知道,keyof但是interface当 Flow 可以获取对象的键时,它只能获取 的键。

Tit*_*mir 8

等价的是keyof类型运算符:

type FormType = keyof typeof foo
Run Code Online (Sandbox Code Playgroud)