type assertion

Telling TypeScript to treat a value as a certain type with the as keyword, without checking that it really is.

In more detail

A type assertion silences the compiler but does nothing at run time, so data that does not match will still crash later. Prefer parsing untrusted data with a schema, which produces a correctly typed value only when the data really matches.

Example

const user = data as User   // no runtime check at all

Related terms

Taught in

References