ericelliott / ericelliott/rtype
this keyword as a dynamic return type
- Dominant language
- JavaScript
- Stars
- 1.1k
- Forks
- 38
- PR merge metrics
- No merged PRs in 30d
Description
related: #68
**example**
You have a fluent interface but one of the method X is slightly restrictive and doesn't return `this` but a subset of its `this`. In this case if the next method Y returns `this` it will share its constraints.
problem: if that method Y may also follow another method Z that returns `this`, its return type becomes dynamic.
solution: introduce a `this` return type
**NB**
It would be impractical to require the user to provide all the possibilities as unions.
It's the job of the static type checker; it should be able to infer the correct type from the current `this`.
**proposal**
```
example(name: Type) => this
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.