If you define
type FAs = [Function, {}];
Then values โโof type FAs will need the first element of type Function , the second element of type {} and the subsequent elements of Function | {} Function | {} . This is how literal types like TypeScript work. From TS docs :
When accessing an element outside the set of known indexes, the union type is used instead:
This should do everything you need except because you can pass the Function value as the third element, etc. array. But actually it would be anyway, since Function compatible with {} .
There is no way around this. In TS, there is no way to determine the type of array, where the first n elements have a specific type (s), and there is an arbitrary number of remaining elements of another specific type.
I am also wondering if the type system supports what is possibly a tuple of arbitrary length.
In fact, the type system only supports tuples of arbitrary length. If you say
type Tuple = [number, number];
this type is compatible with any array of length 2 or more that contains numbers. If you say
type Tuple = [string, number];
this type is compatible with any array of length 2 or longer that has a row as its first element, a second number and a row or number as its third, etc. I would not call the reasons for this behavior "computer-based"; it is more a question of what TS can be checked.
Alternative approach
interface Arglist { [index: number]: object; 0: Function; } const a1: Arglist = [func]; const a2: Arglist = [22];
user663031
source share