TypeScript · Narrowing and unions
Type assertion
Overrides inference. Prefer narrowing or validation; assertions can hide real bugs.
Syntax
value as ShapeExample
Example
const raw = JSON.parse('{"kind":"circle","r":2}') as { kind: string };
console.log(raw.kind);More in this group
Learn this in the course
Reference pages are the quick answer. The course explains the why, shows the full example and ends with a challenge.