为什么打字稿中允许这样做?

时间:2018-11-23 14:31:07

标签: typescript

为什么打字稿允许此代码?

NA

当我实例化通用class Test<T> { private value: T; public setValue(value: T): this { this.value = value; return this; } } const test = new Test(); test.setValue(5); 类而不指定通用参数时,Test变量的类型为test

我认为Test<{}>是一个空类型,如何为它分配一个{}

谢谢

0 个答案:

没有答案
相关问题