Tell the compiler you know more: value as string or angle form <string>value (avoid in JSX files).
Prefer narrowing (typeof, guards) over assertions—assertions can lie and hide bugs.
When assertions are acceptable
After validating runtime shape (schema library) or when DOM APIs return overly wide types (document.getElementById). Document why the assertion is sound in a comment.
Self-check
- Rewrite an
as stringusing atypeofguard instead.
Practice: Apply type-assertions in the playground, then explain type assertions in one sentence without looking at notes.