Skip to content

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

@weswigham

Description

@weswigham

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions