【发布时间】:2021-06-09 16:43:06
【问题描述】:
我有这个代码:
class A<T> {
a(t: T) {
console.log(t);
}
}
class B<T, O extends {b: T}> {
constructor(public a: A<O>) {
}
b(t: T) {
console.log(t)
}
}
const a = new A<{b: number}>(); // type: A<{ b: number; }>
const b = new B(a); // type: B<unknown, { b: number; }>
为什么 TypeScript 将 B 类的方法 b 的参数标记为未知?
【问题讨论】:
-
您的编辑器是否向您显示了一些表明问题的消息?能否添加截图,或复制错误文本?
标签: typescript type-inference typescript-generics