You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class A {
label:string = 'test'
}
class B {
private _a:A
set a(val:A) { this._a = val }
constructor() { this._a = new A() }
}
const b = new B()
b.a.label = 'hello' //b.a will always be undefined due to missing getter, but still somehow gets b.a's type from the setter, and will cause no TS errors
Expected behavior:
Error: no 'a' property on class 'B'
OR
Error: class 'B' is missing a getter for property 'a'
(P.S. maybe b.a should not resolve to type 'A' just because that is the setter type)
Actual behavior:
Compiles fine. Variable has value undefined at runtime.
+1 A getter without a setter is well-defined in TS (readonly) but a setter without a getter should either use some writeonly modifier ( #21759 ) or fail to compile entirely, since TS's type system won't complain and you'll get runtime errors.
TypeScript Version: 3.8.3
Search Terms:
missing getter setter
Code
Expected behavior:
Error: no 'a' property on class 'B'
OR
Error: class 'B' is missing a getter for property 'a'
(P.S. maybe
b.a
should not resolve to type 'A' just because that is the setter type)Actual behavior:
Compiles fine. Variable has value undefined at runtime.
Playground Link:
Playground Link
Related Issues:
#30852
The text was updated successfully, but these errors were encountered: