A parameter or property marked ? also lists undefined in its type

tx0/ts:optional-also-undefinedstrictwarningstyle

What it finds

function draw(color?: string | undefined): ? already adds undefined to the type of a parameter or property, so writing it into the type as well says the same twice.

Properties are reported too, although with exactOptionalPropertyTypes the two forms differ for them, which is why the rule is strict.

From the rule's source, optional_also_undefined.rs.

Example from the rule's tests
function draw(color?: string | undefined) {tx0 reports: ? already allows undefined here  return color;}interface Options {  size?: number | undefined;tx0 reports: ? already allows undefined here  name?: string;}
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:optional-also-undefined" = "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:optional-also-undefined] reason="..."

tx0 explain tx0/ts:optional-also-undefined shows the same in the terminal. Found a false positive? Report it.