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, }); }
Generated using TypeDoc
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, }); }