UNPKG

2.41 kBTypeScriptView Raw
1/**
2 * Common types/interfaces such as Class/Constructor/Options/Callback
3 */
4/**
5 * Interface for classes with `new` operator and static properties/methods
6 */
7export interface Class<T> {
8 new (...args: any[]): T;
9 [property: string]: any;
10}
11/**
12 * Interface for constructor functions without `new` operator.
13 *
14 * @example
15 * ```ts
16 * function Foo(x) {
17 * if (!(this instanceof Foo)) { return new Foo(x); }
18 * this.x = x;
19 * }
20 * ```
21 */
22export interface ConstructorFunction<T> {
23 (...args: any[]): T;
24}
25/**
26 * Constructor type - class or function
27 */
28export type Constructor<T> = Class<T> | ConstructorFunction<T>;
29/**
30 * Objects with open properties
31 */
32export interface AnyObject {
33 [property: string]: any;
34}
35/**
36 * An extension of the built-in Partial<T> type which allows partial values
37 * in deeply nested properties too.
38 */
39export type DeepPartial<T> = Partial<T> | {
40 [P in keyof T]?: DeepPartial<T[P]>;
41};
42/**
43 * Type alias for strongly or weakly typed objects of T
44 */
45export type DataObject<T extends object> = T | DeepPartial<T>;
46/**
47 * Type alias for Node.js options object
48 */
49export type Options = AnyObject;
50/**
51 * Type alias for Node.js callback functions
52 */
53export type Callback<T> = (err: Error | string | null | undefined, result?: T) => void;
54/**
55 * Type for a command
56 */
57export type Command = string | AnyObject;
58/**
59 * Named parameters, such as `{x: 1, y: 'a'}`
60 */
61export type NamedParameters = AnyObject;
62/**
63 * Positional parameters, such as [1, 'a']
64 */
65export type PositionalParameters = any[];
66/**
67 * Count of Model instances that were successful for methods like `updateAll`,
68 * `deleteAll`, etc.
69 */
70export interface Count {
71 count: number;
72}
73/**
74 * JSON Schema describing the Count interface. It's the response type for
75 * REST calls to APIs which return `count`. The type is compatible with
76 * `SchemaObject` from `@loopback/openapi-v3`, which is not an explicit
77 * dependency for `@loopback/repository`.
78 */
79export declare const CountSchema: {
80 type: "object";
81 title: string;
82 'x-typescript-type': string;
83 properties: {
84 count: {
85 type: "number";
86 };
87 };
88};
89/**
90 * Type helper to infer prototype from a constructor function.
91 *
92 * Example: `PrototypeOf<typeof Entity>` is resolved to `Entity`.
93 */
94export type PrototypeOf<Ctor extends Function> = Ctor extends {
95 prototype: infer Proto;
96} ? Proto : never;