typeguard-generator
This is an npm module designed to make it easy to create type guards for an interface.
Usage
npm i typeguard-generator
;
To creare a typeguard you must describe its properties with an interface
interface IMyInterface propA: string; propB?: number; let myInterface: generatorIInterfaceDefinition = propA: type: 'string' propB: type: 'number' optional: true
then use the generateGuard
function to create the typeguard
let test is IMyInterface = generatorgenerateGuard<IMyInterface>myInterface; let test1: any = propA: 'here'; let test2: any = propA: 'here' propB: 8; let test3: any = {};let test4: any = propA: 5; // true, cast as IMyInterface;;// false ;;
The features of the generator are limited at this point, the IInterfaceDefinition should make what is and is not support clear
;