/typescript/

TypeScript part 3 (interface)

2017-03-02 21:05:06

TypeScript

interface Person {
    name: string,
    age?: number
}

function logPerson(person: Person) {
    console.log(person.name);
}

logPerson({name: "Michal", age: 18});
logPerson({name: "Marta"});

JavaScript

function logPerson(person) {
    console.log(person.name);
}
logPerson({ name: "Michal", age: 18 });
logPerson({ name: "Marta" });