Type Assertions
Telling the compiler what you know that it doesn't `as`, the non-null assertion, and the safer `satisfies` operator.
as (type assertion)
Tells the compiler "trust me, treat this value as this type" it does not perform any runtime check or conversion, it just changes what the compiler believes:
Assertions bypass type-checking, so a wrong assertion won't be caught until the code actually runs:
Use assertions sparingly only when you genuinely know more than the compiler can infer (e.g. after a runtime check the compiler can't see, or working with DOM APIs).
Non-null assertion (!)
A special case of assertion: tells the compiler a value is definitely not null/undefined, even though its type says it might be:
This is also just a compile-time promise if you're wrong, it still throws at runtime. Prefer an actual check (if (user) { ... }) or optional chaining (user?.name) when you're not fully certain.
satisfies
A newer operator that validates a value against a type without widening or changing the value's own inferred type giving you both compile-time checking and the most specific inferred type, which plain annotations or as can't do together.
satisfies is especially useful for config objects: you get an error if a value doesn't match the expected shape, while keeping the most precise possible type for later use.