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

Typescript Union Types

Union Types in Typescript allows a variable to have the ability to store a value of several types. We define union types by using a pipe- (|) to separate each of the possible types. Hence, number | string | boolean is the type of a variable, which can have the value that can be a number, a string, or a boolean.

Typescript String, Boolean, Number & Enum Literal types

TypeScript Literal Types restrict the value of a variable to finite valid values. The latest version of Typescript supports the following Literal Types. String Literal Types,Numeric Literal Types,Boolean Literal Types & Enum Literal Types. This is very useful feature which restrict the possible values, that you can store in a variable

TypeScript Null, Undefined & Strict Null Checks

TypeScript has two special values for Null and Undefined. We can assign them to all other types like number, string, etc. Such assignment has been the source of a lot of errors likeTypeErrors or ReferenceErrors in JavaScript. Since the TypeScript Version 2.0. we can make use of strictNullChecks: true in the tsconfig.json, which ensures that the compiler to raise an error if we assign Null and Undefined to other types. In this tutorial, we learn more about Null and Undefined. Their similarities and differences. How to check for null & Undefined etc.

Typescript Never Type

The Typescript Never type represents the type that never happens or the values that never occur. The following are such places where we use the never type. The return type of function that never returns (infinite loop or always throws an error). Variables when narrowed by a Type guard that can never be true

Scroll to Top