#3312Easy

Parameters

Extract function parameter types with TypeScript. Master the infer keyword and function type manipulation in this easy-level challenge on TypeScriptPro.

Extract function parameter types like a pro! 📤

In this easy-level challenge, you'll implement TypeScript's built-in Parameters<T> utility type from scratch. This type extracts the parameter types from a function type and returns them as a tuple. It's an essential tool for working with functions at the type level.

You'll learn how to use conditional types with infer to capture function parameters, a technique that opens the door to powerful function type manipulations in TypeScript.

For this challenge, you will need to change the following code to make the tests pass (no type check errors).

Challenge Instructions: Parameters

Easy

Implement the built-in Parameters<T> generic without using it.

For example:

const foo = (arg1: string, arg2: number): void => {}
 
type FunctionParamsType = MyParameters<typeof foo> // [arg1: string, arg2: number]
Loading...

Video Walkthrough

Detailed Explanation

The Parameters type uses conditional types with infer to extract function parameters.

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

Breaking it down:

This pattern is fundamental for introspecting function types and is used extensively in TypeScript's utility types and advanced type programming.

Share this challenge

Join early, learn faster.

Be the first to access the course, unlock exclusive launch bonuses, and get special early-bird pricing before anyone else.

No spam, unsubscribe at any time. We respect your privacy.

Limited Availability

Only 27 Spots left

Early Access

Get 1 month early access

>75% Off

Pre-Launch discount

This challenge is originally from here.