Is there a way to determine if a tuple is finite or infinite?
I've been working on a solution, but it doesn't cover all cases:
type IsFinite<T extends any[], Finite = true, Infinite = false> = T extends []
? Finite
: T extends (infer Element)[]
? Element[] extends T
? Infinite
: T extends [any, ...infer Rest]
? IsFinite<Rest, Finite, Infinite>
: never
: never
type Foo1 = IsFinite<[string]> // true
type Foo2 = IsFinite<[]> // true
type Foo3 = IsFinite<string[]> // false
type Foo4 = IsFinite<[arg1: string, ...args: string[]]> // false
type Foo5 = IsFinite<[string, ...[string, number], ...string[], string]> // never <- doesn't handle this case