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: instance member function becomes instance member property in type references [outcome: fixed since 3.7.0-dev.20191016] #33747

Closed
bre1470 opened this issue Oct 2, 2019 · 4 comments

Comments

@bre1470
Copy link

bre1470 commented Oct 2, 2019

TypeScript Version: 3.7.0-dev.20191002

Search Terms: instance member property

Code

declare global {
    class A {
        public f(): void;
    }
    class BA extends A {
        public f(): void;
    }
    class CA extends A {
        public f(): void;
    }
    class D extends CA {
        public f: BA['f']; // errors with 3.7
    }
}

export default undefined;

Expected behavior: use declarations without error

Actual behavior: errors with Class 'CA' defines instance member function 'f', but extended class 'D' defines it as instance member property.

Playground Link: https://www.typescriptlang.org/play/?ts=Nightly#code/CYUwxgNghgTiAEBzCB7ARlC8DeAoeB8kUAzifAII76G0AOArmhAJZjwBmAFAJQBc8AG4oWwANw0CAX0lFoZeACEqIAB4AXEADtg5Knlr0mrdt35CR42TNrEFAYRUbtuytUOFGzNp14DhohK0NoR25AAi8GqaOuSO7h7wXiacAsoA2gDkHJkAumLwAPSFUTAwKDDkAO4s6gAW8ADMAHQA7Na4MrhgKFokKBAgzaiIXJkAEiAQqAA08FUVEMAAhJk8ErhqdBXq8KAcUAwQuww6IBwsWiBWQA (compiles there without error)

Related Issues: -

@NoPhaseNoKill
Copy link

I'm getting the same issue, namely when using react lifecycle methods that have an arrow function.

componentWillMount = () => {...}

/*Throws 'Class component'' Props<State, any> defines instance member function componentDidMount, but extended class 'X ' defines it as an instance member property
*/

Error is fixed with:
componentWillMount() {....}

The problem with the workaround, is that to my knowledge it will change what is bound to context of 'this' under certain scenarios. Could someone please clarify on this?

@bre1470
Copy link
Author

bre1470 commented Oct 3, 2019

In your case the this scope might change as arrow functions use the outer scope as they do not have their own.

@seansfkelley
Copy link

seansfkelley commented Oct 16, 2019

This is still the case in 3.7.0-beta. Original issue: #17113.

Edit: this is fixed in nightly already and is working for me.

@bre1470
Copy link
Author

bre1470 commented Oct 17, 2019

Confirmed. The issue is solved for me as well since 3.7.0-dev.20191016.

@bre1470 bre1470 changed the title 3.7: instance member function becomes instance member property in type references 3.7: instance member function becomes instance member property in type references [outcome: fixed since 3.7.0-dev.20191016] Oct 17, 2019
@bre1470 bre1470 closed this as completed Oct 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants