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

AI solution for TypeScript puzzle on BFE.dev
11. implement ConstructorParameters<T>

Here is one possible implementation of MyConstructorParameters<T>:

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

Explanation:

  • T extends new (...args: any) => any ensures that T is a constructor function.
  • ...args: infer P captures the types of the constructor arguments into a tuple P.
  • T extends new (...args: infer P) => any ? P : never uses a conditional type to return P if T extends the expected constructor signature, or never otherwise.

With this implementation, the C type in the example will be correctly inferred as [a: string, b: number, c: boolean].