-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2793-mutable.ts
50 lines (43 loc) · 981 Bytes
/
2793-mutable.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
/**
* 2793 - Mutable
*
* Implement the generic ```Mutable<T>``` which makes all properties in ```T``` mutable (not readonly).
*
* For example
*
* ```typescript
* interface Todo {
* readonly title: string
* readonly description: string
* readonly completed: boolean
* }
*
* type MutableTodo = Mutable<Todo> // { title: string; description: string; completed: boolean; }
*
* ```
*/
/* _____________ Your Code Here _____________ */
type Mutable<T extends object> = {
-readonly [K in keyof T]: T[K];
}
/* _____________ Test Cases _____________ */
import type { Equal, Expect } from '@type-challenges/utils'
interface Todo1 {
title: string
description: string
completed: boolean
meta: {
author: string
}
}
type List = [1, 2, 3]
type cases = [
Expect<Equal<Mutable<Readonly<Todo1>>, Todo1>>,
Expect<Equal<Mutable<Readonly<List>>, List>>,
]
type errors = [
// @ts-expect-error
Mutable<'string'>,
// @ts-expect-error
Mutable<0>,
]