/typescript/

TypeScript part 13 (custom type)

2017-03-04 13:34:43

TypeScript

type Person = {name: string, age: number, address: string[], dev: boolean, sayHello: () => string};

// person = {} <- error

// person = {name:"michal"} <-error

let person: Person = {
    name: "Szalek",
    age: 18,
    address: ["Polska", "Warszawa", "Street 18"],
    dev: true,
    sayHello: function (): string {
        return "Hello"
    }
}

JavaScript

// person = {} <- error
// person = {name:"michal"} <-error
var person = {
    name: "Szalek",
    age: 18,
    address: ["Polska", "Warszawa", "Street 18"],
    dev: true,
    sayHello: function () {
        return "Hello";
    }
};