Typescript: Executor Task Interface

1

I'm trying to make an interface such that some variable, for example, args, corresponds to the arguments of a given function.

export interface ExecutorTask<T extends any[]> {
  args: T;
  thisValue: Object;
  fn: (...args: T) => any;
}

But I have this error:

Typescript
A rest parameter must be of an array type.

Any help would be greatly appreciated. Thanks!

    
asked by tomas 31.01.2018 в 04:12
source

1 answer

1

The problem is that, due to a limitation of Typescript, the generic class T does not detect you as an array, you have to explicitly declare an array type for that parameter. There is even an open task in the official repository of Typescript requesting that this statement be admitted, but for the time being it has not been paid attention . Therefore, the only solution is to change your code to:

export interface ExecutorTask<any[]> {
  args: any[];
  thisValue: Object;
  fn: (...args: any[]) => any;
}
    
answered by 31.01.2018 в 12:31