TypeScript: Type System

Understanding the TypeScript’s type system and some must-know concepts

In this lesson, we are going to learn about the fundamentals of TypeScript and how TypeScript manages types. This lesson includes topics such as type assertion, type interference, type unions, type guards, structural typing, and other important concepts that you should absolutely know about.

Uday Hiwarale
JsPoint
Published in
30 min readJul 25, 2020

--

(source: unsplash.com)

Type Inference

In TypeScript, when initializing a variable with a value, we do not necessarily need to provide the data type for the variable. The TypeScript compiler is smart enough to deduce (infer) the type by looking at the type and shape of the value we are assigning to the variable in the declaration.

(type-inference.ts)

In the above example, we have declared a few variables without an explicit type but with an initial value. When you hover over a variable, TypeScript provides you the interfered type which I have shown you in the comments.

--

--