Skip to content

Property without a setter, typescript isn't catching error when settting #1810

Closed
@RoyM33

Description

@RoyM33

if you create a "property" with a public getter and no setter. if you then try to set that property typescript doesn't tell you this isn't allowed. But it sure will blow up your code.

    private _date: Date;
    public get Date()
    {
        return this._date;
    }

In the above scenario if you do
this.Date = new Date();
typescript allows this without catching anything (no red underbar or error), but the javascript doesn't allow it. Changing the code to the below code works as expected.
this._date = new Date();

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