This solution is generated by ChatGPT, correctness is not guaranteed.

AI solution for TypeScript puzzle on BFE.dev
10. implement Parameters<T>

Here's a possible implementation of MyParameters<T>:

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

Let's break it down:

  • the T extends (...args: infer P) => any conditional type checks whether type T is a function or not. If it is a function, P will be set to the tuple type of its parameters, otherwise, it will be set to never.
  • If T is indeed a function, MyParameters<T> returns its parameter tuple type P, otherwise, it returns never.

With this implementation, we can check the following:

type Foo = (a: string, b: number, c: boolean) => string

type A = MyParameters<Foo> // [a:string, b: number, c:boolean]
type B = A[0] // string
type C = MyParameters<{a: string}> // Error

And we get the expected output and error for types A and C, respectively.