我正在尝试创建一个接口,该接口列出了类应实现的一堆函数。
但是,在实现类时,我遇到了一个奇怪的打字问题Types of parameters XXX and 'args' are incompatible
以下是代码(运行打字稿3.8.3),here is a link to typescript playground
interface ICoreFunctions {
getAll<T>(...args: T[]): any;
}
interface IFirst<F> {
value:F
}
interface ISecond<S> {
data:S
}
class ClsTest<TTest1 extends string> implements ICoreFunctions {
public getAll(valBool:IFirst<boolean>, valString:ISecond<string>, num:number): TTest1 <-----Type 'T' is not assignable to type 'IFirst<boolean>'
{
const t:TTest1 = ""
console.log(valBool, valString,num)
return t
}
}
class Cls2 implements ICoreFunctions {
public getAll():void { <--- no error here
console.log("test2")
}
}