question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Super call of non-method incorrectly allowed if target >= ES6

See original GitHub issue

From https://stackoverflow.com/questions/56775734/error-when-calling-super-method-in-a-typescript-create-react-app-project

TypeScript 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:open
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
RyanCavanaughcommented, Jun 27, 2019

The bug is that it’s allowed, not that it’s disallowed! The code fails at runtime

image

1reaction
fatcerberuscommented, Jun 27, 2019

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found