TypeScript Tutorial #2 - Object Literal Annotations

Pubblicato il: 17 giugno 2021
sul canale di: 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.


In questa pagina del sito puoi guardare il video online TypeScript Tutorial #2 - Object Literal Annotations della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Free Tutorial Wale 17 giugno 2021, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 35 volte e gli è piaciuto 0 spettatori. Buona visione!