Disclaimer: I find it difficult to summarize the problem in the title of the question, so if you have any better suggestions, please let me know in the comments.
Take the following simplified TypeScript class:
class Model {
save():Model {
// save the current instance and return it
}
}
The class Modelhas a method save()that returns an instance of itself: a Model.
We can expand Modelas follows:
class SomeModel extends Model {
}
So it SomeModelinherits save(), but it still returns Model, not SomeModel.
Is there a way, possibly using generics, to set the return type save()to SomeModelon SomeModel, without overriding it inside the inheritance class?