Skip to content

Instantly share code, notes, and snippets.

@nkohari
Last active December 23, 2015 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkohari/6652642 to your computer and use it in GitHub Desktop.
Save nkohari/6652642 to your computer and use it in GitHub Desktop.
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