= "Marco" let integers: Array<number> = [1, 2, 3]; let elem: HTMLElement = document.getElementById('my-elem'); size = "Polo"; // Type 'string' is not assignable to type 'number'.
string; } let user: Person = { name: 'Pedro', surname: 'Gonzales' } // Object literal may only specify known properties, and 'surname' does not exist in type 'Person'.
let user: Person = { name: 'Pedro', surname: 'Gonzales' } as Person // we’re sure that Pedro is a person let user: Person = <Person> { name: 'Pedro', surname: 'Gonzales' };
function Person(name) { this.name = name; } Person.prototype.greet = function () { return 'Hi, my name is ' + this.name; }; return Person; }()); var user = new Person('Rob'); user.greet(); // Hi, my name is Rob
title: string; constructor(name: string, title: string) { super(name); this.title = title; } greet() { return 'You may address me as ' + this.title + ' ' + this.name; } } const importantUser = new ImportantPerson('Von Hammerschmidt', 'Duke'); importantUser.greet(); // You may address me as Duke Von Hammerschmidt
public by default protected name: string; private lastname: string; } const user = new Person(); user.title = 'Mr'; user.name = 'Rob'; // Property 'name' is protected and only accessible within class 'Person' and its subclasses. user.lastname = 'Willson'; // Property 'lastname' is private and only accessible within class 'Person'.