Constructor inference
Concept and syntax
Use a construct signature pattern to extract constructor arguments and the instance type. abstract new also matches abstract constructors for type inspection; it does not authorize constructing an abstract class. A call signature alone is not a construct signature.
Working example
Save each snippet separately as main.ts in a fresh directory with TypeScript 5.8.3. Compile with tsc --strict --target ES2022 --module commonjs --moduleDetection force --skipLibCheck --noEmitOnError main.ts and run accepted snippets with node main.js. Type aliases are erased; assignments and diagnostic checks demonstrate the type relations, not the printed output alone.
type Ctor<T>=T extends abstract new (...a:infer A)=>infer I?[A,I]:never; class Cup{constructor(public size:number){}}const p:Ctor<typeof Cup>=[[3],new Cup(3)]; console.log(p[0][0],p[1].size);Expected output:
3 3Common mistake
Intentionally invalid; compile separately and do not execute.
type Ctor<T>=T extends abstract new (...a:infer A)=>infer I?[A,I]:never; class Cup{constructor(public size:number){}}const p:Ctor<typeof Cup>=[["3"],new Cup(3)];Expected diagnostic: TS2322. The constructor takes a number.
Practice and recap
Try a class with two constructor arguments.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Constructor inference — knowledge check
Check the type transformation, trace output, diagnose a rejected example, and apply the concept to a new case.
Which statement about Constructor inference is accurate?
What is the complete stdout, represented as a JSON string (including newline characters)?
type Ctor<T>=T extends abstract new (...a:infer A)=>infer I?[A,I]:never; class Cup{constructor(public size:number){}}const p:Ctor<typeof Cup>=[[3],new Cup(3)]; console.log(p[0][0],p[1].size);Which diagnostic and explanation match the rejected example under the lesson settings?
type Ctor<T>=T extends abstract new (...a:infer A)=>infer I?[A,I]:never; class Cup{constructor(public size:number){}}const p:Ctor<typeof Cup>=[["3"],new Cup(3)];Which input extracts Cup's construct signature?