in

164 阅读1分钟

in 可以遍历枚举类型

type Keys = 'father' | 'mother' | 'son'

type Person = {
    [k in Keys]: string
}

const jack: Person = {
    father: 'tony',
    mother: 'lily',
    son: 'tom'
}