Closed

Description
Bug Report
π Search Terms
- type check read-only accessor
- compile time check for setter
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about type checking of accessors
β― Playground Link
Playground link with relevant code
π» Code
class Immutable {
get prop(): string {
return 'foo';
}
}
class Mutable {
set prop(value: string) {}
}
class Other {
get prop2(): string {
return 'foo';
}
}
const test = (v: Mutable) => {};
test(new Other());
//Compile error as expected
test(new Immutable());
//No error, but would also expect one
π Actual behavior
Other
correctly causes a compile error as it does not have prop
property. Immutable
passes compiler check even though the prop
property is read-only (just a get
)
π Expected behavior
I would expect both Other
and Immutable
to fail the typing of test
as neither adhere to the structure of Mutable
.
If inside test
I try and set v.prop
when Immutable
is passed in I get a runtime error. I would expect the typing to guard against this.