TypeScript Tutorial #2 - Object Literal Annotations

Veröffentlicht am: 17 Juni 2021
auf dem Kanal: 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.


Auf dieser Seite können Sie das Online-Video TypeScript Tutorial #2 - Object Literal Annotations mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Free Tutorial Wale 17 Juni 2021 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 35 Mal angesehen und es wurde von 0 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!