-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
64 lines (60 loc) · 1.57 KB
/
index.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Any type that can be used as a key of an object.
*
* ```
* const key1: Key = Symbol();
* const key2: Key = 42;
* const key3: Key = "Bart";
* ```
*/
export type Key = keyof any;
/**
* An object containing elements of type T.
*
* ```
* const scores: Dictionary<number> = {
* "Amelia": 4,
* "Riley": 7,
* "April": 5
* };
*
* scores["Xander"] = 3;
* ```
*
* @deprecated Use `Record<TKey, TElement>` or `Map<TKey, TElement>` instead.
*/
export type Dictionary<TElement, TKey extends Key = string> = Record<TKey, TElement>;
/**
* A read-only object containing elements of type T.
*
* ```typescript
* function winner(scores: ReadonlyDictionary<number>): string {
* let winner = "";
* let highScore = 0;
*
* for (const name of Object.keys(scores)) {
* if (scores[name] > highScore) {
* highScore = scores[name];
* winner = name;
* }
* }
*
* return name;
* }
* ```
*
* @deprecated Use `Readonly<Record<TKey, TElement>>` or `ReadonlyMap<TKey, TElement>` instead.
*/
export type ReadonlyDictionary<TElement, TKey extends Key = string> = Readonly<Record<TKey, TElement>>;
/**
* An object containing elements of type T, keyed by numbers.
*
* @deprecated Use `Record<number, T>` or `Map<number, T>` instead.
*/
export type NumberMap<T> = Dictionary<T, number>;
/**
* A read-only object containing elements of type T, keyed by numbers.
*
* @deprecated Use `Readonly<Record<number, T>>` or `ReadonlyMap<number, T>` instead.
*/
export type ReadonlyNumberMap<T> = ReadonlyDictionary<T, number>;