isguard-ts
    Preparing search index...

    Function isType

    • Creates a TypeTypeGuard for an object type based on a template of property type guards. This is the primary function for creating type guards for interfaces and object types.

      Best practice: pass the generic type argument into isType to avoid unexpected optional-field behavior.

      Type Parameters

      • T extends object

        The object type to create a guard for

      Parameters

      • template: TypeGuardTemplate<T>

        An object where each property is a type guard for the corresponding property in T

      Returns TypeTypeGuard<T>

      A type guard for T

      type Person = {
      name: string;
      age: number;
      };

      const isPerson = isType<Person>({
      name: isString,
      age: isNumber,
      });

      isPerson({ name: "Hello", age: 6 }); // true