isguard-ts
    Preparing search index...

    Function isIntersection

    • Creates an IntersectionTypeGuard that checks that the value matches all provided type guards.

      Can be shortened with TypeGuard.and.

      Best practice: use satisfies on the result of isIntersection to ensure the type guard is of the expected intersection type.

      Type Parameters

      • T extends readonly unknown[]

        Array of types in the intersection

      Parameters

      Returns IntersectionTypeGuard<T>

      A type guard for the intersection of all the given type guards

      type A = { a: number };
      type B = { b: string };
      type C = A & B;

      const isA = isType<A>({ a: isNumber });
      const isB = isType<B>({ b: isString });

      const isC = isIntersection(isA, isB) satisfies TypeGuard<C>; // or isA.and(isB)

      isC({ a: 1, b: "hello" }); // true
      isC({ a: 1 }); // false