Bug Report
π Search Terms
override, TS4112
π Version & Regression Information
It happens in 4.4.2 and has been there since the introduction of override keyword (#39669).
β― Playground Link
https://www.typescriptlang.org/play?#code/MYGwhgzhAECC0G8BQ1oHsBuBTATjglgCZbQAuaAyqQQHYDmAFAJSKo5akCuON0A5ADM0aPgG5oAXyQSgA
π» Code
class A {
override toString() { return 'foo'; }
}
π Actual behavior
TS4112: This member cannot have an 'override' modifier because its containing class 'A' does not extend another class.
π Expected behavior
It should be allowed, since the method overrides Object.prototype.toString.
Per ECMAScript spec Β§15.7.12.7, a class without an explicit extends clause would be implicitly inheriting from Object. Therefore, such classes should be allowed to explicitly override methods declared in Object.
Bug Report
π Search Terms
override, TS4112
π Version & Regression Information
It happens in 4.4.2 and has been there since the introduction of
overridekeyword (#39669).β― Playground Link
https://www.typescriptlang.org/play?#code/MYGwhgzhAECC0G8BQ1oHsBuBTATjglgCZbQAuaAyqQQHYDmAFAJSKo5akCuON0A5ADM0aPgG5oAXyQSgA
π» Code
π Actual behavior
TS4112: This member cannot have an 'override' modifier because its containing class 'A' does not extend another class.π Expected behavior
It should be allowed, since the method overrides
Object.prototype.toString.Per ECMAScript spec Β§15.7.12.7, a class without an explicit
extendsclause would be implicitly inheriting fromObject. Therefore, such classes should be allowed to explicitly override methods declared in Object.