Courses / TypeScript
8. Type assertions with `as`
Using the as syntax to assert a type when progressively migrating code.
JavaScript
Type assertions with `as`
A way to tell the TypeScript/JS toolchain what type a value should be when the compiler can't infer it.
"I know this value is a User, but the compiler sees only object—let me tell it explicitly."
Type assertions (using `as`) let you override or narrow the type the compiler assigns to a value without changing runtime behavior; they're a compile-time hint, not a runtime check.
"I know this value is a User, but the compiler sees only object—let me tell it explicitly."
Type assertions (using `as`) let you override or narrow the type the compiler assigns to a value without changing runtime behavior; they're a compile-time hint, not a runtime check.