1 | import type { IObjectOf } from "./object.js";
|
2 | /**
|
3 | * Generic interface for reference types (value wrappers).
|
4 | */
|
5 | export interface IDeref<T> {
|
6 | /**
|
7 | * Returns wrapped value.
|
8 | */
|
9 | deref(): T;
|
10 | }
|
11 | export declare type MaybeDeref<T> = IDeref<T> | T;
|
12 | /**
|
13 | * If `T` is a {@link IDeref}, returns its value type or else `T`.
|
14 | */
|
15 | export declare type Derefed<T> = T extends IDeref<any> ? ReturnType<T["deref"]> : T;
|
16 | /**
|
17 | * Constructs a type with a set of properties `K` of type `T` and
|
18 | * attempts to resolve each given key via {@link Derefed}.
|
19 | *
|
20 | * @example
|
21 | * ```ts
|
22 | * interface Foo {
|
23 | * a: IDeref<string>;
|
24 | * b: IDeref<number>;
|
25 | * c: { d: number };
|
26 | * }
|
27 | *
|
28 | * type Foo2 = DerefedKeys<Foo>;
|
29 | * // { a: string; b: number; c: { d: number; } }
|
30 | *
|
31 | * type Foo3 = DerefedKeys<Foo, "b">;
|
32 | * // { b: number; }
|
33 | * ```
|
34 | */
|
35 | export declare type DerefedKeys<T extends IObjectOf<any>, K extends keyof T = keyof T> = {
|
36 | [P in K]: Derefed<T[P]>;
|
37 | };
|
38 | /**
|
39 | * Returns true iff `x` implements {@link IDeref}.
|
40 | *
|
41 | * @param x -
|
42 | */
|
43 | export declare const isDeref: (x: any) => x is IDeref<any>;
|
44 | /**
|
45 | * If `x` implements {@link IDeref}, returns its wrapped value, else
|
46 | * returns `x` itself.
|
47 | *
|
48 | * @param x -
|
49 | */
|
50 | export declare const deref: <T>(x: MaybeDeref<T>) => T;
|
51 | //# sourceMappingURL=deref.d.ts.map |
\ | No newline at end of file |