UPDATE: TypeScript 4.1 introduced this feature as mentioned by @jcalz.
I am attempting to create a generic type that can traverse a tuple. Initially, I tried using recursion but encountered an error
Type alias 'YourOperator' circularly references itself.
. Here is a basic example of my initial approach:
type VariadicAnd<T extends any[]> = T extends [infer Head, ...infer Tail] ? Head & VariadicAnd<Tail> : unknown
In my specific scenario, I also wanted to apply a transformation to the `Head` by encapsulating it within another generic type. For instance:
type SimpleTransform<T> = { wrapped: T }
type VariadicAndWithTransform<T extends any[]> = T extends [infer Head, ...infer Tail]
? SimpleTransform<Head> & VariadicAndWithTransform<Tail>
: unknown;
Interestingly, while IntelliSense interprets the types correctly, the TypeScript compiler rejects it. I am considering alternative approaches or trying to find a workaround for my recursive implementation.