File: types.ts

package info (click to toggle)
node-typanion 3.14.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 392 kB
  • sloc: javascript: 51; makefile: 2
file content (25 lines) | stat: -rw-r--r-- 849 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
export type BoundCoercionFn = () => BoundCoercionFn;
export type CoercionFn = (v: any) => BoundCoercionFn;
export type Coercion = [string, BoundCoercionFn];

/**
 * Given a Typanion validator, return the type the validator guarantees if it
 * matches.
 */
export type InferType<U> = U extends Trait<infer V> ? V : never;
export type Trait<Type> = {__trait: Type};

export type LooseTest<U> = (value: U, test?: ValidationState) => boolean;
export type StrictTest<U, V extends U> = (value: U, test?: ValidationState) => value is V;

export type LooseValidator<U, V> = LooseTest<U> & Trait<V>;
export type StrictValidator<U, V extends U> = StrictTest<U, V> & Trait<V>;

export type AnyStrictValidator = StrictValidator<any, any>;

export type ValidationState = {
  p?: string,
  errors?: string[],
  coercions?: Coercion[],
  coercion?: CoercionFn,
};