Привязать функцию this к параметру generi c rest - PullRequest
0 голосов
/ 30 января 2020

Следующая функция bindF имеет ошибку типа:

type F<M, AS extends any[]> = (this: M, ...args: AS) => any;

function bindF<M, AS extends any[]>(f: F<M, AS>, m: M) {
    return f.bind(m); // error
}
Overload 1 of 6, '(this: F<M, AS>, thisArg: ThisParameterType<F<M, AS>>): OmitThisParameter<F<M, AS>>', gave the following error.
    Argument of type 'M' is not assignable to parameter of type 'ThisParameterType<F<M, AS>>'.
  Overload 2 of 6, '(this: (this: M, ...args: any[]) => any, thisArg: M, ...args: any[]): (...args: any[]) => any', gave the following error.
    The 'this' context of type 'F<M, AS>' is not assignable to method's 'this' of type '(this: M, ...args: any[]) => any'.
      Types of parameters 'args' and 'args' are incompatible.
        Type 'any[]' is not assignable to type 'AS'.
          'any[]' is assignable to the constraint of type 'AS', but 'AS' could be instantiated with a different subtype of constraint 'any[]'.

Кажется, проблема в том, что нет перегрузки bind для обработки обобщенного c rest параметр AS. Есть ли способ обойти это?

Детская площадка

...