我已经看到一些例子让我觉得它可能会起作用,但我无法让以下工作。下面,C
泛型代表一个类类型,I
泛型代表一个接口类型。但是,return new SomeClass()
抱怨:Type SomeClass is not assignable to type I
。
class SomeFactory implements ISomeFactory {
createSomeModule<C, I>(clas?: C, options?: IFactoryOptions): I {
switch (typeof (clas)) {
case 'SomeClass':
return new SomeClass();
...
}
}
}
这应该像我想的那样工作吗?我错过了什么吗?或者这只是不支持。我正在使用 Typescript 2.10 版运行 VS Code。