-
Notifications
You must be signed in to change notification settings - Fork 0
/
00009-medium-deep-readonly.ts
57 lines (52 loc) · 1.02 KB
/
00009-medium-deep-readonly.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
// ============= Test Cases =============
import type { Equal, Expect } from "./test-utils";
type cases = [Expect<Equal<DeepReadonly<X>, Expected>>];
type X = {
a: () => 22;
b: string;
c: {
d: boolean;
e: {
g: {
h: {
i: true;
j: "string";
};
k: "hello";
};
l: [
"hi",
{
m: ["hey"];
}
];
};
};
};
type Expected = {
readonly a: () => 22;
readonly b: string;
readonly c: {
readonly d: boolean;
readonly e: {
readonly g: {
readonly h: {
readonly i: true;
readonly j: "string";
};
readonly k: "hello";
};
readonly l: readonly [
"hi",
{
readonly m: readonly ["hey"];
}
];
};
};
};
// ============= Your Code Here =============
type DeepReadonly<T> = T extends Record<string, unknown> | unknown[]
? { readonly [P in keyof T]: DeepReadonly<T[P]> }
: T;
const test = [1, 2, 3].map((i) => i + 2);