-
Notifications
You must be signed in to change notification settings - Fork 0
/
03312-easy-parameters.ts
47 lines (35 loc) · 1.17 KB
/
03312-easy-parameters.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
/*
3312 - Parameters
-------
by midorizemi (@midorizemi) #easy #infer #tuple #built-in
### Question
Implement the built-in Parameters<T> generic without using it.
For example:
```ts
const foo = (arg1: string, arg2: number): void => {}
type FunctionParamsType = MyParameters<foo> // [arg1: string, arg2: number]
```
> View on GitHub: https://tsch.js.org/3312
*/
/* _____________ Your Code Here _____________ */
type MyParameters<T extends (...args: any[]) => any> = T extends (
...args: infer Args
) => any
? Args
: never
/* _____________ Test Cases _____________ */
import type { Equal, Expect } from '@type-challenges/utils'
const foo = (arg1: string, arg2: number): void => {}
const bar = (arg1: boolean, arg2: { a: 'A' }): void => {}
const baz = (): void => {}
type cases = [
Expect<Equal<MyParameters<typeof foo>, [string, number]>>,
Expect<Equal<MyParameters<typeof bar>, [boolean, { a: 'A' }]>>,
Expect<Equal<MyParameters<typeof baz>, []>>
]
/* _____________ Further Steps _____________ */
/*
> Share your solutions: https://tsch.js.org/3312/answer
> View solutions: https://tsch.js.org/3312/solutions
> More Challenges: https://tsch.js.org
*/