• Convenience function to implement typeguard for an interface T

    The consistency of the implementation is enforced by the compiler.

    Example:

    interface I { foo: number; bar: string; }

    // Ok: function isI(arg: unknown): arg is I { return isInstanceOf(arg, { foo: isString, bar: isNumber, }); }

    // Error (typeguard for bar is missing): function isI(arg: unknown): arg is I { return isInstanceOf(arg, { foo: isString, }); }

    // Error (typeguard for bar has wrong type): function isI(arg: unknown): arg is I { return isInstanceOf(arg, { foo: isString, bar: isString, }); }

    // Error (baz is not part of I): function isI(arg: unknown): arg is I { return isInstanceOf(arg, { foo: isString, bar: isNumber, baz: isBoolean, }); }

    Type Parameters

    • T

    Parameters

    • arg: unknown
    • typeGuardMap: {
          [index in string | number | symbol]: ((arg) => arg is T[index])
      }

    Returns arg is T

Generated using TypeDoc