`override` keyword not honored for methods of `Object` on classes with no `extends`, `Object` `super` members missing
See original GitHub issueBug 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.
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:
- Created a year ago
- Reactions:4
- Comments:6 (4 by maintainers)
noImplicitOverride
today has the goodness that it works just like jumping in checkers: If you can writeoverride
, you mustTurning that from a boolean (must write, cannot write) to a tristate (must write, may write, cannot write) is a big can of worms.
Every JS programmer should know that
class Foo {}
extends fromObject
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 totrue
(at least for strict mode)?