Skip to content

The compiler should prohibit overriding only one setter if there is a getter/setter pair in the parent class. #48201

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

Closed
barkunas opened this issue Mar 10, 2022 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@barkunas
Copy link

barkunas commented Mar 10, 2022

Bug Report

🔎 Search Terms

The compiler should prohibit overriding only one setter if there is a getter/setter pair in the parent class.

🕗 Version & Regression Information

This is the behavior in every version I tried, and I reviewed the FAQ for entries about override getters/setters

Playground Link with absent getter

💻 Code

class Main {
    protected _aaa: boolean = false
    set aaa(value: boolean) {
        this._aaa = value;
    }
    get aaa(): boolean {
        return this._aaa;
    }
}

class SubMain0 extends Main {
}
class SubMain1 extends Main {
    override set aaa(value: boolean) {
        this.aaa = value;
    }
}
class SubMain2 extends Main {
    override get aaa(): boolean {
        return this._aaa;
    } 
}

console.log(new SubMain0().aaa); // false
console.log(new SubMain1().aaa); // undefined - Bug
console.log(new SubMain2().aaa); // false

🙁 Actual behavior

After override SubMain class lost "aaa" property

🙂 Expected behavior

SubMain class must use a getter from a parent class
or
The TS compiler should throw an error that a getter/setter pair should override together

@barkunas barkunas changed the title The compiler should prohibit overriding only one getter/setter if there is a getter/setter pair in the parent class. The compiler should prohibit overriding only one setter if there is a getter/setter pair in the parent class. Mar 10, 2022
@MartinJohns
Copy link
Contributor

Sounds like #47581.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Mar 10, 2022
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants