diff options
Diffstat (limited to 'src/checkable.ts')
-rw-r--r-- | src/checkable.ts | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/checkable.ts b/src/checkable.ts index b6ef49fac..c8cc27b26 100644 --- a/src/checkable.ts +++ b/src/checkable.ts @@ -72,6 +72,13 @@ export namespace Checkable { return target; } + function checkBoolean(target: any, prop: Prop, path: Path): any { + if (typeof target !== "boolean") { + throw new SchemaError(`expected boolean for ${path}, got ${typeof target} instead`); + } + return target; + } + function checkAnyObject(target: any, prop: Prop, path: Path): any { if (typeof target !== "object") { @@ -269,6 +276,11 @@ export namespace Checkable { chk.props.push({ propertyKey: propertyKey, checker: checkString }); } + export function Boolean(target: Object, propertyKey: string | symbol): void { + let chk = mkChk(target); + chk.props.push({ propertyKey: propertyKey, checker: checkBoolean }); + } + function mkChk(target: any) { let chk = target[chkSym]; |