Skip to content

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

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
myitcv opened this issue Aug 8, 2015 · 3 comments
Closed

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

myitcv opened this issue Aug 8, 2015 · 3 comments

Comments

@myitcv
Copy link

myitcv commented Aug 8, 2015

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?

@myitcv myitcv changed the title Missing getter/setter does not generate compile error Accessing missing getter/setter does not generate compile error Aug 8, 2015
@myitcv
Copy link
Author

myitcv commented Aug 8, 2015

Modified title to be more accurate

@kitsonk
Copy link
Contributor

kitsonk commented Aug 8, 2015

Related/solved by long standing issue #12

@myitcv
Copy link
Author

myitcv commented Aug 9, 2015

Thanks for the pointer, specifically it's a duplicate of #295

@myitcv myitcv closed this as completed Aug 9, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants