Open
Description
π Search Terms
"setter only", "setter-only"
π Version & Regression Information
- This behavior is present in the current version of TypeScript, 5.4.4
β― Playground Link
π» Code
class Foo {
set bar(baz: string) { }
}
const foo = new Foo();
const value: string = foo.bar; // This assignment should not be allowed, foo.bar will always be undefined!
π Actual behavior
There is no error reported during type-checking.
π Expected behavior
The type-checking should report an error for the assignment in the last line as foo.bar
will always be undefined.
Additional information about the issue
#21759 is related, but that issue proposes a whole new language feature, this issue is solely about the lack of a type error.