Skip to content
Sarj Code Standards

no-invalid-typed-mutation

Keep native object mutation APIs from writing incompatible values into declared property types.

Why

Object.assign, Reflect.set and property descriptors accept values that a normal typed property assignment rejects. They can invalidate a domain object's contract while subsequent reads retain its original type.

Fix

Use an assignment that satisfies the declared property type, or construct and validate a complete replacement. Preserve any deliberate construction or external compatibility contract; do not cast away the incompatibility.

Examples

Before — flagged Do not bypass field compatibility through a generic mutation API
src/count.ts
const counter: { count: number } = { count: 1 };
Object.assign(counter, { count: "invalid" });
counter.count.toFixed();
After — preferred Preserve the declared field contract
src/count.ts
const counter: { count: number } = { count: 1 };
Object.assign(counter, { count: 2 });

References