【发布时间】:2019-03-28 01:12:43
【问题描述】:
我正在尝试提取通用字符串文字类型,但打字稿推断只返回类型字符串。
所以从技术上讲,一旦将字符串文字类型传递给函数,我们就不能再提取它了。
type Key<T extends string> = { key: T };
declare function getKey<T extends string>(key: T): Key<T>;
let someKey = getKey('check');
declare function updateWithKey<T, K extends string>(key: T): T extends Key<K> ? K : never;
let someUpdatedKey = updateWithKey(someKey); // Shouldn't be 'check'?
这是Playground中的代码
【问题讨论】:
标签: typescript inference