Skip to content

No error when attempting to read a write-only property #11596

@battmanz

Description

@battmanz

TypeScript Version: 2.0.3

Code

// This works as expected
class Demo1 {
  get foo() {
    return 'hi';
  }
}

let d1 = new Demo1();
d1.foo = 'wat'; // An error is given (as it should be) because foo is read-only.

// This does NOT work as expected
class Demo2 {
  private _foo: string;

  set foo(foo: string) {
    this._foo = foo;
  }
}

let d2 = new Demo2();
console.log(d2.foo); // No error, but there should be because foo is write-only.

Expected behavior:
A compiler error should be given when attempting to read a write-only property.

Actual behavior:
There is no compiler error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions