Navigate back to the homepage

How to define object in typescript?

Infinitbility
TypeScript
March 28th, 2022 · 1 min read
keep affilitate

Hi Friends 👋,

Welcome to Infinitbility ❤️!

This tutorial is part of the below series.

TypeScript define variable

  1. How to define type in typescript?
  2. How to define array in typescript?
  3. How to define object in typescript?
  4. 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.

1type User = {
2 id: int,
3 name: string;
4 isActive: boolean;
5};

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

1type User = {
2 id: int,
3 name: string;
4 isActive: boolean;
5};
6
7const user: User = {
8 id: 1,
9 name: "infintbility",
10 isActive: true
11}

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?

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

melio affilitate

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

How to define array in typescript?

TypeScript, create array example with diffrent data type.

March 27th, 2022 · 1 min read

How to define type in typescript?

TypeScript, Define data type of data syntax example.

March 26th, 2022 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]