Given the following code:
class foo {
protected mBar: string;
public get Bar(): string {
return this.mBar;
}
}
function foobar(): void {
var myFoo: foo = new foo();
myFoo.Bar = "hello";
}
foobar();
Why doesn't the line myFoo.Bar = "hello";
generate a compiler error? I would expect a compiler error since foo only defines a get Bar() but NOT a set Bar(). Instead, the compiler says nothing, and the resulting javascript runs, but fails silently. There's no indication by either the compiler or at runtime that the setter did not work as expected. Shouldn't this situation be flagged by the typescript compiler?
EDIT: Just to provide some context, this occurred by accident. I forgot to define the setter, and then proceeded to waste a bit of time trying to figure out why my assignment wasn't working as expected. If the compiler had simply complained saying I was trying to assign to a property when no setter was defined it would have saved some wasted effort.