TypeScript

Initializing static fields in a static block in TypeScript

TypeScriptClassesStatic Blocksadvanced

What this snippet does

Static initialization blocks run once when the class is initialized, allowing complex setup logic for static properties.

Expected output

42

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 →