mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-11-29 17:51:46 +00:00
add generics for spected
This commit is contained in:
Vendored
+16
-8
@@ -4,20 +4,28 @@
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
declare function spected<ROOTINPUT, SPEC = Spec<ROOTINPUT>>(spec: SPEC, input: ROOTINPUT): Result<ROOTINPUT, SPEC>;
|
||||
declare function spected<ROOTINPUT, SPEC = SpecObject<ROOTINPUT, ROOTINPUT>>(spec: SPEC, input: ROOTINPUT): Result<ROOTINPUT, SPEC>;
|
||||
|
||||
export type Predicate<INPUT, ROOTINPUT> = (value: INPUT, inputs: ROOTINPUT) => boolean;
|
||||
type Predicate<INPUT, ROOTINPUT> = (value: INPUT, inputs: ROOTINPUT) => boolean;
|
||||
|
||||
export type ErrorMsg<INPUT> =
|
||||
type ErrorMsg<INPUT> =
|
||||
| (string | number | boolean | symbol | null | undefined | object)
|
||||
| ((value: INPUT, field: string) => any);
|
||||
|
||||
export type Spec<INPUT, ROOTINPUT = any> = Partial<{[key in keyof INPUT]: SpecValue<INPUT[key], ROOTINPUT>}>;
|
||||
type SpecArrayElement<INPUT, ROOTINPUT> = [Predicate<INPUT, ROOTINPUT>, ErrorMsg<INPUT>];
|
||||
|
||||
export type SpecValue<INPUT, ROOTINPUT = any> =
|
||||
| ReadonlyArray<[Predicate<INPUT, ROOTINPUT>, ErrorMsg<INPUT>]>
|
||||
| ((value: INPUT) => any)
|
||||
| Spec<INPUT, ROOTINPUT>;
|
||||
export type SpecArray<INPUT, ROOTINPUT> = ReadonlyArray<SpecArrayElement<INPUT, ROOTINPUT>>;
|
||||
|
||||
export type SpecFunction<INPUT, ROOTINPUT> = INPUT extends ReadonlyArray<infer U>
|
||||
? (value: INPUT) => ReadonlyArray<SpecArray<U, ROOTINPUT>>
|
||||
: (value: INPUT) => SpecObject<INPUT, ROOTINPUT>;
|
||||
|
||||
export type SpecObject<INPUT, ROOTINPUT> = Partial<{[key in keyof INPUT]: SpecValue<INPUT[key], ROOTINPUT>}>;
|
||||
|
||||
export type SpecValue<INPUT, ROOTINPUT> =
|
||||
| SpecArray<INPUT, ROOTINPUT>
|
||||
| SpecFunction<INPUT, ROOTINPUT>
|
||||
| SpecObject<INPUT, ROOTINPUT>;
|
||||
|
||||
export type Result<INPUT, SPEC> = {[key in keyof INPUT]: true | any[] | Result<INPUT[key], any>};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user