Visit completeTypeScript roadmap

Type Assertions

Type assertions in TypeScript are a way to tell the compiler to treat a value as a specific type, regardless of its inferred type.

There are two syntaxes for type assertions in TypeScript:

  • The “angle-bracket” syntax: <T>value
  • The “as” syntax: value as T

For example:

let num = 42;

// using angle-bracket syntax
let str = <string>num;

// using as syntax
let str2 = num as string;

In both examples, num is a number, but the type assertions tell the compiler to treat the value as a string.

Learn more from the following links:

Found any mistakes? Help us improve by updating the file here..

Community is the 6th most starred project on GitHub and is visited by hundreds of thousands of developers every month.

RoadmapsBest PracticesGuidesVideosFAQsYouTube

roadmap.shbyKamran Ahmed

Community created roadmaps, articles, resources and journeys to help you choose your path and grow in your career.

© ·Terms·Privacy·


The leading DevOps resource for Kubernetes, cloud-native computing, and the latest in at-scale development, deployment, and management.