typescript:具有泛型函数集合的泛型接口:参数XXX和'args'的类型不兼容

时间:2020-04-29 11:47:10

标签: typescript generics

我正在尝试创建一个接口,该接口列出了类应实现的一堆函数。 但是,在实现类时,我遇到了一个奇怪的打字问题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")
      }
  }

0 个答案:

没有答案