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.

`override` keyword not honored for methods of `Object` on classes with no `extends`, `Object` `super` members missing

See original GitHub issue

Bug Report

All classes without an extends clause implicitly extend from Object. However the override keyword does not work when overriding members of Object, and I believe it should for consistency, semantics, and display of developer intent.

image

Furthermore, TypeScript chooses to hide super members of Object, and the following valid JavaScript has an unexpected type error:

class Foo {
  toString() {
      return super.toString() + ' ' + 123 // Error: 'super' can only be referenced in a derived class. (2335)
  }
}

new Foo().toString() // This works just fine in JavaScript.

The class is implicitly derived (from Object), and super.toString exists.

🔎 Search Terms

🕗 Version & Regression Information

I don’t think it ever worked?

⏯ Playground Link

Playground link with relevant code

Playground link with relevant code

🙁 Actual behavior

No type information is present for inherited Object members inside a class without extends.

Possibly related: even on any plain object like a POJO, intellisense in VS Code does not show helpful autocompletion for Object members.

🙂 Expected behavior

It should show the full picture, because it is valid JavaScript.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:4
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
RyanCavanaughcommented, May 24, 2022

noImplicitOverride today has the goodness that it works just like jumping in checkers: If you can write override, you must

Turning that from a boolean (must write, cannot write) to a tristate (must write, may write, cannot write) is a big can of worms.

0reactions
trusktrcommented, Aug 26, 2022

It seems like if you’re explicit enough to be specifying that toString is an override, then writing class Foo extends Object should also be a thing you’d want to write.

Every JS programmer should know that class Foo {} extends from Object by default (because it effectively does!). But that’s a good workaround for base class authors only too.

Some people are importing classes from libraries, for example, and forking a library just to add extends Object to a library’s base class is not ideal.

What about an new option noImplicitObjectOverrides that defaults to false, then deprecate implicit Object overrides, and eventually switch the default to true (at least for strict mode)?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is super.super.method(); not allowed in Java?
If your method overrides one of its superclass's methods, you can invoke the overridden method through the use of the keyword super. Don't...
Read more >
super - JavaScript - MDN Web Docs - Mozilla
The super keyword is used to access properties on an object literal or class's [[Prototype]], or invoke a superclass's constructor.
Read more >
Overriding and Hiding Methods (The Java™ Tutorials ...
The ability of a subclass to override a method allows a class to inherit from a superclass whose behavior is "close enough" and...
Read more >
Subclassing and Inheritance - Learning Java, 4th Edition [Book]
A class in Java can be declared as a subclass of another class using the extends keyword. A subclass inherits variables and methods...
Read more >
3. Data model — Python 3.11.1 documentation
Methods also support accessing (but not setting) the arbitrary function attributes on the underlying function object. User-defined method objects may be created ...
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