-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
40 lines (33 loc) · 787 Bytes
/
index.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
// https://www.youtube.com/watch?v=U1EygIpjAEM
interface Todo {
title: string;
description: string;
}
interface Todo2 {
title: string;
description: string;
address: {
street: string;
houseNumber: number;
};
}
type MyReadonly<TInput> = {
readonly [Key in keyof TInput]: TInput[Key];
};
type MyResult = MyReadonly<Todo2>;
// type MyResult = {
// readonly title: string;
// readonly description: string;
// readonly address: {
// street: string;
// houseNumber: number;
// };
// }
const todo: MyReadonly<Todo> = {
title: "Hey",
description: "foobar",
};
// @ts-expect-error
todo.title = "Hello"; // Error: cannot reassign a readonly property
// @ts-expect-error
todo.description = "barFoo"; // Error: cannot reassign a readonly property