TypeScript

A type guard that lies about the actual type in TypeScript

TypeScriptType GuardsUser-Defined Type Guardsbeginner

What this snippet does

TypeScript trusts the type predicate blindly, leading to runtime crashes if the logic is incorrect.

Expected output

TypeError: val.toUpperCase is not a function

Why practise typing this

Typing type guards 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 →