Closed
Description
I was originally looking at the migration guide on how to fix accessors overriding properties in TS -> #33509
Part of that guidance was using object.defineProperty and defining the getter/setter over there but hit a strange compiler error.
TypeScript Version: 3.8.3
Search Terms:
- object define property false positive
- unread variable define property
Code
export class Foo {
private _value: string | undefined;
constructor() {
Object.defineProperty(this, "value", {
get() {
return this._value;
}
});
}
}
Expected behavior:
No compiler errors as I am defining a setter for the _value so the value is being read somewhere
Actual behavior:
'_value' is declared but its value is never read.
If I remove _value
I get
Property '_value' does not exist on type 'Foo'. Did you mean 'value'?
Related Issues: