Utility to reduce depth of TypeScript's internal type instantiation stack.
Example:
type A<T> = { item: T }type Test<T> = A< A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<T>>>>>>>>>>>>>>>>>>>>>>>>>// type Error = Test<number> // Type instantiation is excessively deep and possibly infinite.ts (2589) Copy
type A<T> = { item: T }type Test<T> = A< A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<T>>>>>>>>>>>>>>>>>>>>>>>>>// type Error = Test<number> // Type instantiation is excessively deep and possibly infinite.ts (2589)
To fix this, we can use DrainOuterGeneric:
DrainOuterGeneric
type A<T> = DrainOuterGeneric<{ item: T }>type Test<T> = A< A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<T>>>>>>>>>>>>>>>>>>>>>>>>>type Ok = Test<number> // Ok Copy
type A<T> = DrainOuterGeneric<{ item: T }>type Test<T> = A< A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<T>>>>>>>>>>>>>>>>>>>>>>>>>type Ok = Test<number> // Ok
Utility to reduce depth of TypeScript's internal type instantiation stack.
Example:
To fix this, we can use
DrainOuterGeneric: