interface NullSchema { type: 'null' } interface BooleanSchema { type: 'boolean' } interface NumberSchema { type: 'number' } interface StringSchema { type: 'string' } type LeafSchema = NullSchema | BooleanSchema | NumberSchema | StringSchema interface ArraySchema> | ObjectSchema> { type: 'array' items: T } type ObjectProps = { [K in string]: LeafSchema | ArraySchema> | ObjectSchema> | ObjectSchema } interface ObjectSchema { additionalProperties?: boolean type: 'object' properties: T required: R[] } interface ExtractedSchemaArray extends Array> {} declare type ExtractedSchemaObject = { [K in keyof T]: (K extends R ? ExtractSchemaType : ExtractSchemaType | undefined) } declare type ExtractSchemaType = ( Type extends NullSchema ? null : Type extends BooleanSchema ? boolean : Type extends NumberSchema ? number : Type extends StringSchema ? string : Type extends ArraySchema ? ExtractedSchemaArray : Type extends ObjectSchema ? ExtractedSchemaObject : never ) declare type GenericSchema = ( { type: 'string' | 'number' | 'boolean' | 'null' } | { type: 'array', items: GenericSchema } | { type: 'object', properties: ObjectProps } ) declare namespace factory { interface ValidationError { field: string message: string value: unknown type: string } } declare function createValidator (schema: ObjectSchema, options?: any): ((input: unknown, options?: any) => input is { [K in keyof T]: (K extends R ? ExtractSchemaType : ExtractSchemaType | undefined) }) & { errors: factory.ValidationError[] } declare function createValidator (schema: T, options?: any): ((input: unknown, options?: any) => input is ExtractSchemaType) & { errors: factory.ValidationError[] } declare function createFilter (schema: ObjectSchema, options?: any): ((input: { [K in keyof T]: (K extends R ? ExtractSchemaType : ExtractSchemaType | undefined) }, options?: any) => { [K in keyof T]: (K extends R ? ExtractSchemaType : ExtractSchemaType | undefined) }) declare function createFilter (schema: T, options?: any): ((input: ExtractSchemaType, options?: any) => ExtractSchemaType) declare type Factory = (typeof createValidator) & { filter: typeof createFilter } declare const factory: Factory export = factory