TypeScript

Accessing instance properties in a static block in TypeScript

TypeScriptClassesStatic Blocksadvanced

What this snippet does

Static blocks run in the context of the class constructor, not an instance, so 'this' refers to the class itself, not instance properties.

Expected output

Compile Error: Property 'inst' does not exist on type 'typeof C'.

Why practise typing this

Typing classes code builds muscle memory for the symbols and indentation TypeScript uses most, which prose-based typing tests never cover. DevType measures your words per minute and accuracy on this snippet and tracks the individual characters you mistype, so later lessons can target them.

More TypeScript practice

Browse all TypeScript snippets →