Given the following interfaces:
interface Person {
constructor: Function;
getFullName(): string;
}
interface PersonConstructor {
new (firstName: string, lastName: string): Person;
prototype: Person;
createPerson(firstName: string, lastName: string): Person;
}
I want to custom-write a class using JS rather than TS, like so:
var Person = (() => {
function Person(firstName: string, lastName: string) {
var _firstName = firstName;
var _lastName = lastName;
this.getFullName = () => _firstName + " " + _lastName;
}
Person.createPerson = (firstName: string, lastName: string): Person => new Person(firstName, lastName);
return Person;
})();
But I get the following error:
Property 'createPerson' does not exist on type '(firstName: string, lastName: string) => void'
I would also like to be able to use my custom JS as a base class in TypeScript...
class FamousPerson extends Person {
}
But I get this error...
Type '(firstName: string, lastName: string) => void' is not a constructor function type.
How do I get my custom JS to respect my interfaces?
Note: the interfaces follow the same constructor (static interface) pattern adopted in TS 1.4