Is there a way to tell TypeScript that a static method returns an object that called the method?
I have this base class:
export default class model {
public static create() {
let t = new this() as this
// set extra information here
return t
}
}
I then extend the class like this:
export default class purchases extends model { /* extra methods */ }
I then call it like this:
let p = purchases.create({ my: 'options' })
TypeScript then tells me that p
is of type model
when actually it should be of type purchases
.
When I cast t
to this
or say public static create(): this
I get this error:
A 'this' type is available only in a non-static member of a class or interface.
What can I do to say that "This static method returns an instance of the object that called it"?