Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
MLoughry opened this issue Oct 7, 2019 · 3 comments · Fixed by #34494
Closed

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

MLoughry opened this issue Oct 7, 2019 · 3 comments · Fixed by #34494
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@MLoughry
Copy link

MLoughry commented Oct 7, 2019

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:

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Oct 8, 2019
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.7.1 milestone Oct 8, 2019
@sandersn
Copy link
Member

I looked at the change from TS 3.0 again and found that it was supposed to remove only this error but actually removed it as well as the opposite:

class B {
  foo = () => null
}
class C extends B {
  foo() {
    return null
  }
}

I restored both errors in #33509 while adding new errors -- I noticed dead code and confused an intern's first check-in with a broken change.

I'll take this error (property-overrides-method) back out, but leave in the error for method-overrides-property.

@sandersn sandersn added the Fix Available A PR has been opened for this issue label Oct 15, 2019
@MLoughry
Copy link
Author

Thanks for the quick fix, @sandersn

@ulrichb
Copy link

ulrichb commented Oct 18, 2019

Hmm, this was released in TS@next ~ 3 days ago, but since typescript@3.7.0-dev.20191018 the same error appeared again :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants