Assertions silence the compiler. They do not make you right.
Direct answer
A type assertion uses as Type to tell TypeScript to treat a value as a different type. It has no runtime effect. If you are wrong, errors appear at runtime. Prefer type guards, which check the value for real.
Examples
const input = document.querySelector("#name") as HTMLInputElement;
console.log(input.value);
const el = document.getElementById("app")!; // non-null assertion
Safer pattern
const input = document.querySelector("#name");
if (input instanceof HTMLInputElement) {
console.log(input.value);
}
When assertions are reasonable
- You know something the compiler cannot, such as a DOM element that definitely exists.
- Working with untyped third-party data after validation.
Where Teyro fits
Teyro's TypeScript for Beginners course turns this into short lessons you can play in a few minutes a day. It has 20 lessons, and you can start free.
The bottom line
Use assertions rarely and prefer checks.



