TypeScript

Setting a readonly ID in the constructor in TypeScript

TypeScriptClassesReadonly Modifierbeginner

What this snippet does

Immutable timestamps or IDs can be assigned once upon creation and never modified thereafter.

Expected output

1970-01-01T00:00:00.000Z

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 →