Hi Friends đź‘‹,

Welcome to Infinitbility ❤️!

This tutorial is part of the below series.

TypeScript define variable

How to define type in typescript?

How to define array in typescript?

How to define object in typescript?

How to define array of objects in typescript?

Let start Part 3: How to define object in typescript?

In this tutorial, we will create objects in typescript, but before creating objects we have to write their property data type.

Let’s define their property data type.

To define the type, TypeScript provides a type keyword you can also use interface, and some developers define a class for this.

But here, we used type.

type User = {
    id: int,
    name: string;
    isActive: boolean;
};

in the above code, we have to define object property data type, which we are going to use in creating objects.

type User = {
    id: int,
    name: string;
    isActive: boolean;
};

const user: User = {
    id: 1,
    name: "infintbility",
    isActive: true
}

Okay, now we know when we want to create an object then first we have to create their type.

Next := How to define array of objects in typescript?