A property has a setter but no getter, so reading it gives undefined

tx0/ts:setter-without-getterstrictwarningsmell

What it finds

A property with a setter and no getter can be written but reads as undefined, which surprises every caller that reads back what it wrote. Either a getter belongs with it, or a method says that the value goes in only.

Reported are setters in object literals and classes without a getter of the same name, and the same staticness, in the same literal or class body. Computed names are left alone.

From the rule's source, setter_without_getter.rs.

Example from the rule's tests
export const config = {  set level(value: number) {tx0 reports: level has a setter but no getter    console.warn(value);  },  get mode() {    return 1;  },  set mode(value: number) {    console.warn(value);  },};export class Store {  static get size() {    return 0;  }  set size(value: number) {tx0 reports: size has a setter but no getter    console.warn(value);  }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/ts:setter-without-getter" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/ts:setter-without-getter] reason="..."

tx0 explain tx0/ts:setter-without-getter shows the same in the terminal. Found a false positive? Report it.