TypeScript Tutorial #2 - Object Literal Annotations

Published: 17 June 2021
on channel: Free Tutorial Wale
35
0

#Annotations #Typescript

In JavaScript, the fundamental way that we group and pass around data is through objects. In TypeScript, we represent those through object types.

function greet(person: { name: string; age: number }) {
return "Hello " + person.name;
}

or they can be named by using either an interface

interface Person {
name: string;
age: number;
}

function greet(person: Person) {
return "Hello " + person.name;
}

or a type alias.

type Person = {
name: string;
age: number;
};

function greet(person: Person) {
return "Hello " + person.name;
}

Each property in an object type can specify a couple of things: the type, whether the property is optional, and whether the property can be written to.


On this page of the site you can watch the video online TypeScript Tutorial #2 - Object Literal Annotations with a duration of hours minute second in good quality, which was uploaded by the user Free Tutorial Wale 17 June 2021, share the link with friends and acquaintances, this video has already been watched 35 times on youtube and it was liked by 0 viewers. Enjoy your viewing!