Skip to content

[3.7.0-beta] Child class cannot override base member function with arrow function #33855

Closed
@MLoughry

Description

@MLoughry

TypeScript Version: 3.7.0-dev.20190927 (works on 3.7.0-dev.20190926)

Search Terms:
TS2424, member function

Code

class BaseClass {
    foo() {
        return null;
    }
}

class ChildClass extends BaseClass {
    foo = () => null;
}

Expected behavior:
In 3.6.3 and <=3.7.0-dev.20190926, this code would compile without error

Actual behavior:

error TS2424: Class 'BaseClass' defines instance member function 'foo', but extended class 'ChildClass' defines it as instance member property.

8   foo = () => null;
    ~~~

Since our code has to compile down to ES5 (to support IE11), we need to perform some sort of method binding on methods that reference this. With this change, it means we would need to make all possibly-overridable member functions arrow functions

Playground Link: http://www.typescriptlang.org/play/index.html?ts=3.7-Beta#code/MYGwhgzhAEBCkFMDC4rQN4Cho+gMwHsCAKASg21yoCcEAXAV2oDtpmGQQBuSnAX0wDMoSDCQALAJYgAJilHQEADzoJmMmPAjJUMLFUIFoAXmhkTAPjYdugoA

Related Issues:

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions