TypeScript Tutorial #2 - Object Literal Annotations

Опубликовано: 17 Июнь 2021
на канале: 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.


На этой странице сайта вы можете посмотреть видео онлайн TypeScript Tutorial #2 - Object Literal Annotations длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Free Tutorial Wale 17 Июнь 2021, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 35 раз и оно понравилось 0 зрителям. Приятного просмотра!