/typescript/

TypeScript part 11 (object type)

2017-03-04 13:04:41

Auto object type

TypeScript

let person = {
    name: "Michał",
    age: 18
};

// ----------------

// person = {} <- error

// ----------------

// person = {
//     lick: "Michał", <- error
//     age: 18
// }

JavaScript

let person: {name: string, age: number} = {
    name: "Michał",
    age: 18
};

// ----------------

// person = {} <- error

// ----------------

// person = {
//     lick: "Michał", <- error
//     age: 18
// }

Definition of object type

TypeScript

let person: {name: string, age: number} = {
    name: "Michał",
    age: 18
};

// ----------------

// person = {} <- error

// ----------------

// person = {
//     lick: "Michał", <- error
//     age: 18
// }

JavaScript

var person = {
    name: "Michał",
    age: 18
};
// ----------------
// person = {} <- error
// ----------------
// person = {
//     lick: "Michał", <- error
//     age: 18
// }