UNPKG

@muban/muban

Version:

Writing components for server-rendered HTML

64 lines (63 loc) 2.09 kB
import type { Predicate, Primitive } from 'isntnt'; import type { ConstructorType, PropTypeDefinition, SourceOptions } from './propDefinitions.types'; declare type OptionalValue<T> = T & { isOptional: true; missingValue: true; }; declare type Default<T, V> = T & { isOptional: true; default: V; }; declare type Optional<T extends PropTypeDefinition> = T & { optional: Validate<OptionalValue<T>> & Source<OptionalValue<T>>; defaultValue: <U extends ConstructorType<T['type']> | undefined>(value: ConstructorType<T['type']> extends Primitive ? U : () => U) => Validate<Default<T, typeof value>> & Source<Default<T, typeof value>>; }; declare type Validator<T, V extends Predicate<any>> = T & { validator: V; }; declare type Validate<T extends PropTypeDefinition> = T & { validate: <U extends ConstructorType<T['type']> | undefined | null>(predicate: Predicate<U>) => Source<Validator<T, typeof predicate>>; }; declare type SourceValue<T, V> = T & { sourceOptions: V; }; declare type Source<T extends PropTypeDefinition> = T & { source: (options: SourceOptions) => SourceValue<T, typeof options>; }; declare type ShapeType<T, V> = T & { shapeType: V; }; declare type Shape<T extends PropTypeDefinition> = T & { shape: <U extends Function>() => ShapeType<T, U>; }; declare type GenericType<T extends PropTypeDefinition> = T & Optional<T> & Validate<T> & Source<T>; declare type FunctionType<T extends PropTypeDefinition> = T & Shape<T> & { optional: Shape<OptionalValue<T>>; }; export declare const propType: { string: GenericType<{ type: StringConstructor; }>; number: GenericType<{ type: NumberConstructor; }>; boolean: GenericType<{ type: BooleanConstructor; }>; date: GenericType<{ type: DateConstructor; }>; object: GenericType<{ type: ObjectConstructor; }>; array: GenericType<{ type: ArrayConstructor; }>; func: FunctionType<{ type: FunctionConstructor; }>; any: GenericType<{ type: any; }>; }; export {};