ts-type-check
Version:
Check json value based of Typescript type in string
23 lines (22 loc) • 714 B
TypeScript
export type Type = 'string' | 'number' | 'Date' | 'null' | 'boolean' | 'true' | 'false' | string;
export declare class TypeCheckError extends TypeError {
statusCode: number;
status: number;
constructor(message: string);
}
export type TypeCheckOptions = {
casualBoolean?: boolean;
};
declare abstract class TypeChecker {
abstract type: string;
abstract check(data: any, options?: TypeCheckOptions): void;
compile(): TypeChecker;
}
export declare function parseTsType(type: Type): TypeChecker;
/**
* only check for json-compatible types
*
* @throws TypeCheckError if failed
* */
export declare function checkTsType(type: Type, data: any, options?: TypeCheckOptions): void;
export {};