R18BREAKINGfunction

Parameter Mutability Narrowed

Flags when a parameter loses its readonly constraint. Callers passing readonly data will fail because the function now expects mutable data.


Applies to

TypeScriptRust

Why it matters

If a function previously accepted readonly T[] and now expects T[], callers passing readonly arrays will get a type error.

Example

Before (readonly)
// processor.ts
export function process(data: readonly number[]): number {
  return data.reduce((a, b) => a + b, 0);
}
After (mutable)
// processor.ts (BREAKING — mutability narrowed)
export function process(data: number[]): number {
  data.sort(); // now mutates the input
  return data.reduce((a, b) => a + b, 0);
}

What you see in the terminal

$ npx dg check

  [BREAKING] process (signature_change)
  src/processor.ts:2
  Parameter 'data' mutability narrowed. Callers passing readonly arrays will fail type checking.

How detection works

The classifier detects when a parameter's type text loses 'readonly', 'Readonly', or 'ReadonlyArray' keywords.

Real-world scenario

A function that used to accept readonly arrays now mutates its input and no longer accepts readonly data. Callers with `const data: readonly number[] = [1,2,3]` will get compilation errors.

Edge cases

  • In Rust, this corresponds to &T -> &mut T
  • Only detects explicit readonly/Readonly annotations