Skip to content

Implementing only a setter is enough to implement a getter #33650

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
weswigham opened this issue Sep 27, 2019 · 1 comment
Closed

Implementing only a setter is enough to implement a getter #33650

weswigham opened this issue Sep 27, 2019 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@weswigham
Copy link
Member

weswigham commented Sep 27, 2019

And vice-versa.

Inspired by #33621

Code

declare class Properties {
    set val(x: number);
}

class BadProps implements Properties {
    private _val: number = 42;
    get val() {
        return this._val;
    }
}

declare class Properties2 {
    get val(): number;
}

class BadProps2 implements Properties2 {
    private _val: number = 42;
    set val(x: number) {
        this._val = 2;
    }
}

const x: Properties = new BadProps();
x.val;
x.val = 12;

const x2: Properties2 = new BadProps2();
x2.val;
x2.val = 12;

Expected behavior:
Error on BarProps for incorrectly implementing Properties.
Error on BarProps2 for incorrectly implementing Properties2.

Actual behavior:
No error, even with "useDefineForClassFields": true.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Oct 8, 2019
@RyanCavanaugh
Copy link
Member

We have eleventydozen issues on this already; let's reopen an existing one if we want to change how it works.

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

2 participants