4 ms·
> This type can be used in classes and interfaces to represent some type that is a subtype of the containing type (rather than the containing type itself) Coul
by TazeTSchnitzel 11y ago
> This type can be used in classes and interfaces to represent some type that is a subtype of the containing type (rather than the containing type itself)
Could that not be achieved by having covariant return types instead?
- Arnavion 11y agoSure, but that would require every subtype to override every method of the base type with a narrower return type, and do nothing except delegate to the base type in the body. It would be tedious boilerplate. Since the base type's implementation already returns `this`, it makes sense to be able to annotate the method as returning `this` and get the benefit automatically.
- deleted 11y ago[deleted]
- TazeTSchnitzel 11y agoAh, yes, that's a problem. In PHP, there's been some debate as to whether or not to support `static` (similar in function to TypeScript's `this`) as a return type, and that's one of the arguments in favour.