共计 276 个字符,预计需要花费 1 分钟才能阅读完成。
type Obj = {xxxFoo?: number ,xxxBar?: number}
declare function func(obj: Obj): void
type Suffix = 'Foo'
const s: Suffix = 'Foo'
func({[`xxx${'Bar'}`]: 2,
[`yyy${'Foo'}`]: 2, // 这行会报错,符合预期
[`yyy${s}`]: 3, // 但这行为什么不会报错???!!![`xxx${s}` satisfies keyof Obj]: 4
})
为什么那行不会报错,和上一行到底有什么区别啊?我也是服了,所有上火的地方都上在 TypeScript 上。
正文完