【发布时间】:2019-08-10 15:05:31
【问题描述】:
鉴于我们有一个通用的可索引类型,我怎样才能只检索其值的类型以便能够缩小到只有一些键?
// imagine check is a function and its second argument only allows the property `a` as it's string and raise an error if 'b' is passed
const test2 = check({ a: 'string', b: 22 }, 'b'); // error only 'a' is allowed
const test2 = check({ a: 'str', b: 'str2' }, 'b'); // ok returns 'str2'
【问题讨论】:
标签: typescript