TypeScript Advanced Types

Type Assertion in TypeScript
TypeScript

Type Assertion in TypeScript

Type Assertion allows us to override the compiler determined type in our code. It is something similar to type casting in other languages. except that it does not restructure or modify the type in any way. The Type Assertion in TypeScript is a compile-time feature

Nullable Types Non Nullable Types in TypeScript
TypeScript

Nullable Types / Non Nullable Types in TypeScript

Typescript types are Nullable Types. i.e you can assign Null & undefined to any of the types. The compiler will not throw any error. But from the Typescript version 2.0, we can define Non Nullable types with the –strictNullChecks flag on. The strictNullChecks is flag is set to false by default. But, when set to true in tsconfig.json it stops us from assigning the null & undefined to a type. Thus converting the types into Non Nullable types.

Typescript Instanceof Type Guard
TypeScript

Typescript Instanceof Type Guard

instanceof is a type Guard, which checks if a value is an instance of a class or a constructor function. It also acts as a Type Guard, helping us the infer the type correctly in the scope

Scroll to Top