In short, I am very confused why this code compiles without error:
class Foobar {
#data = 0
set data(val: number) { this.#data = val }
// (Notice there is no getter for "data")
}
let foobar = new Foobar()
// Call the setter for data, no problemo
foobar.data = 123
// Call the getter for data, compiler should not allow this imo
console.log(foobar.data) // Prints "undefined"
- Is this a bug in the typescript compiler? I can't find anywhere that this issue is mentioned. Or is my example working as intended (did I miss something?).
- Is there some way (using eslint rules or tsc) to catch this erroneous code?