TypeScript Tutorial #2 - Object Literal Annotations

Publicado em: 17 Junho 2021
no canal de: 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.


Nesta página do site você pode assistir ao vídeo on-line TypeScript Tutorial #2 - Object Literal Annotations duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Free Tutorial Wale 17 Junho 2021, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 35 vezes e gostou 0 espectadores. Boa visualização!