Object.assign copies into an object literal where a spread would

tx0/ts:object-assign-copystrictwarningstyle

What it finds

Object.assign({}, defaults, options) copies objects into a fresh one, which the object spread { ...defaults, ...options } writes as a literal, with types that TypeScript follows more precisely.

Reported are calls of the global Object.assign whose first argument is an object literal and which have no spread arguments. The fix writes the spread; it is unsafe, since assign runs setters, and __proto__ in a source sets the prototype where a spread copies an ordinary property.

From the rule's source, object_assign_copy.rs.

Example from the rule's tests
export function merge(defaults: object, options: object, target: object) {  const a = Object.assign({}, defaults, options);tx0 reports: copies into a fresh object  const b = Object.assign(target, options);  return [a, b];}
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:object-assign-copy" = "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:object-assign-copy] reason="..."

tx0 explain tx0/ts:object-assign-copy shows the same in the terminal. Found a false positive? Report it.