-
Notifications
You must be signed in to change notification settings - Fork 0
/
03312-easy-parameters.ts
35 lines (26 loc) · 1.01 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
/*
3312 - Parameters
-------
by midorizemi (@midorizemi) #easy #infer #tuple #built-in
### Question
Implement the built-in Parameters<T> generic without using it.
> View on GitHub: https://tsch.js.org/3312
*/
/* _____________ Your Code Here _____________ */
type MyParameters<T extends (...args: any[]) => any> = T extends (...args: infer A) => any ? A : 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
*/