Disclosure

Most of the problems under my TypeHero Challenges folder were either obtained from typehero.dev or from type-challenges repo. Purpose of these articles are just to document my approaches for my easy reference. Please visit the respective links for more info.

Link to original

Problem Description

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]

Solutions

Approach

type MyParameters<T extends (...args: any[]) => any> = T extends (...args: infer Params) => any
	? Params
	: never;