Can Typescript support the implementation of an infinite Array (not a Tuple) with a type that depends on the previous element of the array?
Here is a sample pseudo-typescript code:
class B<T, U> {}
function foo<X, Y>(...args: [B<X, Z0>, B<Z0, Z1>, B<Z1, Z2>, ..., B<ZN, Y>]) {}
foo<string, number>(new B<string, number>, new B<number, boolean>, new B<boolean, number>); // Correct
foo<string, number>(new B<string, number, new B<number, boolean>); // Incorrect
foo<string, number>(new B<string, number>, new B<boolean, number>); // Incorrect
What should be substituted for "
[B<X, Z0>, B<Z0, Z1>, B<Z1, Z2>, ..., B<ZN, Y>]
" to make this function? Is it feasible at all?
Your insight is appreciated!