Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In TypeScript, why is it not an error to access (get) property that only has a setter?

Tags:

typescript

Why does this compile? (TS v2.0.3)

class SetterOnly {
  set prop(v) {
    let x = this.prop;
  }
}

I would expect this.prop to generate a compile-time error ...

like image 312
tallaxes Avatar asked Oct 12 '16 01:10

tallaxes


1 Answers

This is a known issue: https://github.com/Microsoft/TypeScript/issues/814

We're definitely not bothering with write-only properties. This is not common enough to justify complicating the type system with it.

like image 137
Shaun Luttin Avatar answered Nov 15 '22 22:11

Shaun Luttin