Type Alias RecursiveIntersect<T, U>

RecursiveIntersect<T, U>: T & (T extends (infer Y)[]
    ? (Y & U)[] & U
    : T extends AnyRecord
        ? {
            [P in keyof T]: T[P] extends (infer R)[]
                ? RecursiveIntersect<R, U>[] & U
                : T[P] extends AnyRecord
                    ? RecursiveIntersect<T[P], U>
                    : T[P] & U
        } & U
        : U)

Intersect type recursively. The recursion terminates at level 7 due to design limit of TypeScript.

Normal use case is intersecting betwee two object types. While it works for value types and top level array, top level array does not recursive into the elements. NOTE: in latest TypeScript, undefined is not an accepted value. The resulting type would be never

Type Parameters

  • T
  • U