Support this
pseudo-params in classes, and enforce subtyping on structural class statics
#1761
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch adds support for a
this
pseudo-param on class methods (static and non-static). With the syntaxsomeMethod(this: this & I,...
users can impose requirement beyond "is subtype of the enclosing class," the current behavior. Some goofiness becomes admissible too, e.g.someMethod(this: {})
--just don't be goofy (maybe a warning is warranted if the pseudo-param's type is not a subtype of the enclosing class). I have a use case where the value in this extension lies in chaining of static methods, not non-statics, so I've extended class subtyping to structural class statics (InstanceT ~> SuperT still ignores subtyping of statics). I feel like I'm on solid ground after a chat with @jeffmo and @avikchaudhuri on IRC, although during that discussion I forgot to contrast ES5 and Node inheritance against ES6 inheritance. I recall in the past that @samwgoldman and I disagreed on whether class statics should subtype.Node's inheritance (
util.inherit
) and the ad hoc inheritance of ES5 (SomeClass.prototype = Object.create(ParentClass.prototype, {...})
without SomeClass.proto = ParentClass) do not chain class statics. Subtyping statics is biased toward ES6 inheritance, whereas the status quo is biased toward Node and ad hoc inheritance.Closes #807, #1369, #1704, #1705