ConstructorParameters and InstanceType
Concept and syntax
ConstructorParameters<C> extracts a construct signature argument tuple, and InstanceType<C> extracts its instance type. Use typeof Class to pass the constructor side; the class name in a type position normally refers to instances. Abstract constructors are supported for inspection.
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.
class Ticket{constructor(public id:number,public label:string){}} type Args=ConstructorParameters<typeof Ticket>; type Item=InstanceType<typeof Ticket>;const a:Args=[2,"tea"]; const t:Item=new Ticket(...a); console.log(t.id,t.label);Expected output:
2 teaCommon mistake
Intentionally invalid; compile separately and do not execute.
class Ticket{constructor(public id:number,public label:string){}} type Args=ConstructorParameters<typeof Ticket>; type Item=InstanceType<typeof Ticket>;const a:Args=["2","tea"];Expected diagnostic: TS2322. The first constructor argument is numeric.
Practice and recap
Compare InstanceType<typeof Ticket> with Ticket.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
ConstructorParameters and InstanceType — knowledge check
Check the type transformation, trace output, diagnose a rejected example, and apply the concept to a new case.
Which statement about ConstructorParameters and InstanceType is accurate?
What is the complete stdout, represented as a JSON string (including newline characters)?
class Ticket{constructor(public id:number,public label:string){}} type Args=ConstructorParameters<typeof Ticket>; type Item=InstanceType<typeof Ticket>;const a:Args=[2,"tea"]; const t:Item=new Ticket(...a); console.log(t.id,t.label);Which diagnostic and explanation match the rejected example under the lesson settings?
class Ticket{constructor(public id:number,public label:string){}} type Args=ConstructorParameters<typeof Ticket>; type Item=InstanceType<typeof Ticket>;const a:Args=["2","tea"];What does InstanceType<typeof Ticket> describe?