-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
Description
题目
题目链接:MyParameters
实现 MyParameters
,获取函数的参数类型
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>, []>>
];
答案
方法一
type MyParameters<Fn> = Fn extends (...args: infer Args) => void ? Args : never;