Last active
December 23, 2015 14:59
-
-
Save nkohari/6652642 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person { | |
constructor(public name : string) { } | |
} | |
class Employee extends Person { | |
constructor(name: string, public employer: Employer) { | |
super(name); | |
} | |
} | |
class Employer extends Person { | |
public employees: Array<Employee>; | |
constructor(name: string) { | |
super(name); | |
this.employees = new Array<Employee>(); | |
} | |
employ(employee: Employee) { | |
employee.employer = this; | |
this.employees.push(employee); | |
} | |
} | |
function getEmployers(employees: Array<Employee>): Array<Employer> { | |
return employees.map(e => e.employer); | |
} | |
var people = new Array<Person>(); | |
people.push(new Person('Jim')); | |
people.push(new Person('Jane')); | |
people.push(new Person('Bob')); | |
var employers = getEmployers(people); | |
// error TS2082: Supplied parameters do not match any signature of call target: | |
// Type 'Person' is missing property 'employer' from type 'Employee'. | |
// error TS2087: Could not select overload for 'call' expression. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment