Skip to content

Accessing missing getter/setter does not generate compile error #4237

Closed
@myitcv

Description

@myitcv

Consider:

class Apple {
    private size: number;

    constructor(size: number) {
        this.size = size;
    }

    get Size(): number {
        return this.size;
    }
}

let a: Apple = new Apple(4);
console.log(a.Size);
a.Size = 5; // should this should throw a compile time error?

It strikes me that the attempted assignment to a.Size should produce a compile time error.

Instead we learn about it at runtime (target es6 with v1.6.0-dev.20150806)

[Error: Cannot set property Size of #<Apple> which has only a getter]

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions