Super call of non-method incorrectly allowed if target >= ES6
See original GitHub issueTypeScript Version: 3.6.0-dev.20190624
Search Terms:
- es5
- super
- arrow method
Code
class Foo {
public bar = () => { }
}
class SubFoo extends Foo {
public bar = () => { super.bar(); }
}
With target: "es5"
Expected behavior:
No errors. Call to super
is allowed.
Actual behavior:
See error on super.bar()
Only public and protected methods of the base class are accessible via the 'super' keyword.
Everything works fine using normal (non-arrow) methods. It also works with "target": "es6"
Playground Link:
Related Issues:
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:6 (4 by maintainers)
Top Results From Across the Web
12. Callable entities in ECMAScript 6 - Exploring JS
Ways of calling in ES6. 12.2.1. Calls that can be made anywhere; 12.2.2. Calls via super are restricted to specific locations; 12.2.3. Non-method...
Read more >ES6 functions, arrow functions and 'this' in an ES6 class
An arrow function expression has a shorter syntax than a function expression and does not have its own this, arguments, super, or new.target....
Read more >The `super` keyword doesn't work as it should? - ES Discuss
I am wanting to duplicate the prototype chains of ES6 classes, but I have no reliable (afaik) way to make the super keyword...
Read more >A closer look at super-references in JavaScript and ... - 2ality
prototype. Super-references (including super-calls) are a feature of ECMAScript 6 which allows one to write describe() much more succinctly:
Read more >Quick Practical Guide for ES6: Part 2 - Modus Create
If you are already using fat arrow functions in ES6, you know how easy ... and does not have its own this, arguments,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The bug is that it’s allowed, not that it’s disallowed! The code fails at runtime
I don’t understand how this can work anyway, since arrow functions don’t have their own
super
binding - they close over the one from outside. Since the arrow function doesn’t occur inside a method body,super
shouldn’t even exist in that scope?