.call or .apply passes the same this that a plain call would

tx0/ts:call-with-same-thisstrictwarningstyle

What it finds

obj.method.call(obj, a) and fn.call(undefined, a) pass the this that a plain call obj.method(a) or fn(a) passes anyway, so .call only adds noise. The same holds for .apply with an array literal of arguments.

Reported are .call and .apply on a method whose object is written the same way as the first argument, and on a plain function name with undefined as the first argument (null differs in strict code); for .apply the arguments must be an array literal without spreads. Objects whose evaluation may have effects are left alone. The fix, which is safe, writes the plain call.

From the rule's source, call_with_same_this.rs.

Example from the rule's tests
export function run(obj: { method(a: number): void }, fn: (a: number) => void) {  obj.method.call(obj, 1);tx0 reports: .call passes the this  fn.call(undefined, 2);tx0 reports: .call passes the this  obj.method.apply(obj, [3]);tx0 reports: .apply passes the this  obj.method.call(other, 4);  fn.call(null, 5);}declare const other: object;
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:call-with-same-this" = "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:call-with-same-this] reason="..."

tx0 explain tx0/ts:call-with-same-this shows the same in the terminal. Found a false positive? Report it.