UNPKG

1.5 kBTypeScriptView Raw
1declare module 'mongoose' {
2
3 type Unpacked<T> = T extends (infer U)[] ?
4 U :
5 T extends ReadonlyArray<infer U> ? U : T;
6
7 type UnpackedIntersection<T, U> = T extends null ? null : T extends (infer A)[]
8 ? (Omit<A, keyof U> & U)[]
9 : keyof U extends never
10 ? T
11 : Omit<T, keyof U> & U;
12
13 type MergeType<A, B> = Omit<A, keyof B> & B;
14
15 /**
16 * @summary Converts Unions to one record "object".
17 * @description It makes intellisense dialog box easier to read as a single object instead of showing that in multiple object unions.
18 * @param {T} T The type to be converted.
19 */
20 type FlatRecord<T> = { [K in keyof T]: T[K] };
21
22 /**
23 * @summary Checks if a type is "Record" or "any".
24 * @description It Helps to check if user has provided schema type "EnforcedDocType"
25 * @param {T} T A generic type to be checked.
26 * @returns true if {@link T} is Record OR false if {@link T} is of any type.
27 */
28type IsItRecordAndNotAny<T> = IfEquals<T, any, false, T extends Record<any, any> ? true : false>;
29
30/**
31 * @summary Checks if two types are identical.
32 * @param {T} T The first type to be compared with {@link U}.
33 * @param {U} U The seconde type to be compared with {@link T}.
34 * @param {Y} Y A type to be returned if {@link T} & {@link U} are identical.
35 * @param {N} N A type to be returned if {@link T} & {@link U} are not identical.
36 */
37type IfEquals<T, U, Y = true, N = false> =
38 (<G>() => G extends T ? 1 : 0) extends
39 (<G>() => G extends U ? 1 : 0) ? Y : N;
40
41}