generated from garronej/ts-ci
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathid.d.ts
36 lines (36 loc) · 1016 Bytes
/
id.d.ts
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
26
27
28
29
30
31
32
33
34
35
36
/** https://docs.tsafe.dev/id */
export declare const id: <T>(x: T) => T;
/**
* Ensure that a that a specific type that we are declaring extends a more generic type
*
* Use case example 1:
*
* type MyObject = {
* p1: string;
* p2: string;
* a: string;
* b: string;
* };
*
* We want to define a type that consist in an union of
* all the property name that are letters:
*
* type AlphabeticalKeys = Id<keyof MyObject, "a" | "b">;
*
* Here AlphabeticalKeys is "a" | "b" but it's better than
* simply writing it explicitly as we get autocompletion
* and we can't include a property name that does not exist on MyObject.
*
* Use case example 2:
*
* We want to declare object type that only take string or number
* as key value:
*
* export type MyObject = Id<Record<string, string | number>, {
* p1: string;
* p2: number;
* }>;
*
* If later on someone adds "p3": string[] he will get a type error.
* */
export type Id<Generic, Specific extends Generic> = Specific;