UNPKG

ts-predicate

Version:

TypeScript predicates and assertions library

44 lines (43 loc) 942 B
/** * ObjectWithNullableProperty type */ type ObjectWithNullableProperty<O extends object, K extends string> = O & { [property in K]: K extends keyof O ? O[K] : unknown; }; /** * ObjectWithProperty type */ type ObjectWithProperty<O extends object, K extends string> = O & { [property in K]: K extends keyof O ? NonNullable<O[K]> : unknown; }; /** * PopulatedArray type */ type PopulatedArray<Type> = [Type, ...Array<Type>]; /** * ArrayConstraints interface */ interface ArrayConstraints<Type> { /** * minLength */ minLength?: number; /** * itemGuard */ itemGuard?: (item: unknown) => item is Type; } /** * StringConstraints interface */ interface StringConstraints { /** * minLength */ minLength?: number; /** * maxLength */ maxLength?: number; } export type { ArrayConstraints, ObjectWithNullableProperty, ObjectWithProperty, PopulatedArray, StringConstraints };