首页 > 其他分享 >[Typescript] 14. Easy - Parameters

[Typescript] 14. Easy - Parameters

时间:2022-09-04 00:02:07浏览次数:44  
标签:Typescript const 14 Parameters arg1 arg2 number _____________ type

Implement the built-in Parameters generic without using it.

For example:

const foo = (arg1: string, arg2: number): void => {}

type FunctionParamsType = MyParameters<typeof foo> // [arg1: string, arg2: number]

 

/* _____________ 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>, []>>,
]

 

标签:Typescript,const,14,Parameters,arg1,arg2,number,_____________,type
From: https://www.cnblogs.com/Answer1215/p/16654003.html

相关文章