Static and instance sides
Concept and syntax
A class name in a type position denotes its instance type. typeof ClassName describes the constructor value, including static members. Static members belong to the constructor rather than each instance. Use the appropriate side when accepting a constructor or an instance.
Working example
Save each snippet separately as main.ts in a fresh directory. Compile with tsc --strict --target ES2022 --module commonjs --moduleDetection force --skipLibCheck --noEmitOnError main.ts, then run the accepted example with node main.js. Forced module detection isolates snippet names from global declarations.
class Box {static label="box";constructor(public count:number){}}const C:typeof Box=Box;const b:Box=new C(3);console.log(C.label,b.count);Expected output:
box 3C is a constructor value with a static label. new C(3) produces an instance with count; it does not copy the static label into the instance.
Common mistake
Intentionally invalid; compile separately and do not execute.
class Box {static label="box";count=3;}const b:Box=new Box();console.log(b.label);Expected diagnostic: TS2576. label belongs to the constructor. Use Box.label, not b.label.
Practice and recap
Write a function accepting typeof Box and instantiate it inside.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Static and instance sides — knowledge check
Check the contract, trace output, and diagnose an invalid example.
Which statement about this lesson’s concept is accurate?
What is the complete stdout, represented as a JSON string (including newline characters)?
class Box {static label="box";constructor(public count:number){}}const C:typeof Box=Box;const b:Box=new C(3);console.log(C.label,b.count);Which diagnostic and explanation match the rejected example under the lesson settings?
class Box {static label="box";count=3;}const b:Box=new Box();console.log(b.label);