UNPKG

hi-datatype-operation

Version:

TypeScript 原生类型守卫生成器,自动同步类型定义与运行时验证逻辑。支持装饰器语法、类型谓词组合与泛型约束验证,提供 VS Code 智能提示插件。

40 lines (35 loc) 2.54 kB
type Primitive = string | number | boolean | symbol | null | undefined; type NonNullablePrimitive = Exclude<Primitive, null | undefined>; type Nuneric = number | string; declare const isString: (val: unknown) => val is string; declare const isNumber: (val: unknown) => val is number; declare const isBoolean: (val: unknown) => val is boolean; declare const isNull: (val: unknown) => val is null; declare const isUndefined: (val: unknown) => val is undefined; declare const isNumeric: (val: unknown) => val is Nuneric; declare const isPrimitive: (val: unknown) => val is Primitive; declare const isNonNullablePrimitive: (val: unknown) => val is NonNullablePrimitive; declare const isOneOf: <T extends unknown[]>(...validators: { [K in keyof T]: (val: unknown) => val is T[K]; }) => (val: unknown) => val is T[number]; declare class TypeDetector { private value; constructor(value: unknown); get isString(): boolean; get isNumber(): boolean; matches<T>(validator: (val: unknown) => val is T): boolean; } declare const detect: (value: unknown) => TypeDetector; declare const isArrayLike: (val: unknown) => val is ArrayLike<unknown>; declare const isUniformArray: <T>(arr: unknown, typeCheck: (val: unknown) => val is T) => arr is T[]; declare const isTuple: <T extends unknown[]>(arr: unknown, ...typeChecks: { [K in keyof T]: (val: unknown) => val is T[K]; }) => arr is T; type ObjectStructure = Record<string, (val: unknown) => boolean>; type EmptyStrictObject = Record<string, never>; type StrictObject = Record<string, unknown>; type DateType = "undefined" | "null" | "boolean" | "number" | "string" | "symbol" | "function" | "array" | "date" | "regexp" | "promise" | "error" | "object"; declare function getDataType(data: any): DateType; declare const isObjectLike: (val: unknown) => val is object; declare const isStrictObject: (val: unknown) => val is StrictObject; declare const isEmptyObject: (val: unknown) => val is EmptyStrictObject; declare const isNotEmptyObject: (val: unknown) => val is StrictObject; declare const matchStructure: (obj: unknown, structure: ObjectStructure) => boolean; declare const isFunction: (val: unknown) => val is Function; export { type DateType, type NonNullablePrimitive, type Nuneric, type Primitive, TypeDetector, detect, getDataType, isArrayLike, isBoolean, isEmptyObject, isFunction, isNonNullablePrimitive, isNotEmptyObject, isNull, isNumber, isNumeric, isObjectLike, isOneOf, isPrimitive, isStrictObject, isString, isTuple, isUndefined, isUniformArray, matchStructure };