-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created

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.
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created