3 ms·
> It won't work if each method returns a new instance, such as methods of immutable collections. TS' this type does not allow that either. You have to return `
by sjrd 11y ago
> It won't work if each method returns a new instance, such as methods of immutable collections.
TS' this type does not allow that either. You have to return `this`, and nothing else.
This can be explained by inheritance. If you extend a class with a method returning a `this` type, but not returning `this`, somehow you should be forced to override that method. But you probably don't want that.
Also, the `this` type introduced by TS is basically equivalent to Scala's `this.type`.
- Arnavion 11y agoD'oh! You're right of course.