UNPKG

1.13 kBTypeScriptView Raw
1/**
2 * Typing system for LoopBack
3 */
4import { Options } from '../common-types';
5export interface Type<T> {
6 /**
7 * Name of the type
8 */
9 name: string;
10 /**
11 * Test if the given value is an instance of this type
12 * @param value - The value
13 */
14 isInstance(value: any): boolean;
15 /**
16 * Generate the default value for this type
17 */
18 defaultValue(): T | null | undefined;
19 /**
20 * Check if the given value can be coerced into this type
21 * @param value - The value to to be coerced
22 * @returns A flag to indicate if the value can be coerced
23 */
24 isCoercible(value: any, options?: Options): boolean;
25 /**
26 * Coerce the value into this type
27 * @param value - The value to be coerced
28 * @param options - Options for coercion
29 * @returns Coerced value of this type
30 */
31 coerce(value: any, options?: Options): T | null | undefined;
32 /**
33 * Serialize a value into json
34 * @param value - The value of this type
35 * @param options - Options for serialization
36 */
37 serialize(value: T | null | undefined, options?: Options): any;
38}