-
Notifications
You must be signed in to change notification settings - Fork 0
/
1367-remove-index-signature.ts
75 lines (58 loc) · 1.52 KB
/
1367-remove-index-signature.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
65
66
67
68
69
70
71
72
73
74
75
/*
1367 - Remove Index Signature
-------
by hiroya iizuka (@hiroyaiizuka) #medium #object-keys
### Question
Implement `RemoveIndexSignature<T>` , exclude the index signature from object types.
For example:
```
type Foo = {
[key: string]: any;
foo(): void;
}
type A = RemoveIndexSignature<Foo> // expected { foo(): void }
```
> View on GitHub: https://tsch.js.org/1367
*/
/* _____________ Your Code Here _____________ */
type RemoveIndexSignature<T> = { [
k in keyof T as string extends k
? never
: number extends k
? never
: symbol extends k
? never : k
]: T[k]
};
/* _____________ Test Cases _____________ */
import type { Equal, Expect } from '@type-challenges/utils'
type Foo = {
[key: string]: any
foo(): void
}
type Bar = {
[key: number]: any
bar(): void
0: string
}
const foobar = Symbol('foobar')
type FooBar = {
[key: symbol]: any
[foobar](): void
}
type Baz = {
bar(): void
baz: string
}
type cases = [
Expect<Equal<RemoveIndexSignature<Foo>, { foo(): void }>>,
Expect<Equal<RemoveIndexSignature<Bar>, { bar(): void; 0: string }>>,
Expect<Equal<RemoveIndexSignature<FooBar>, { [foobar](): void }>>,
Expect<Equal<RemoveIndexSignature<Baz>, { bar(): void; baz: string }>>,
]
/* _____________ Further Steps _____________ */
/*
> Share your solutions: https://tsch.js.org/1367/answer
> View solutions: https://tsch.js.org/1367/solutions
> More Challenges: https://tsch.js.org
*/