Comment déclarer un objet dans TypeScript
/*They can be anonymous*/
function greet(person: { name: string; age: number }) {
return "Hello " + person.name;
}
/*or named using an interface*/
interface Person {
name: string;
age: number;
}
function greet(person: Person) {
return "Hello " + person.name;
}
/*or with a type alias*/
type Person = {
name: string;
age: number;
};
function greet(person: Person) {
return "Hello " + person.name;
}
MitchAloha