Skip to content

wide-param ​

A parameter of a wide context type that the function uses only through one or two field paths: shippingCost(shop: Shop) that reads shop.state.cart and shop.rates.perKg, and nothing else of the shop. An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.

Why: a function that takes the whole context can read (and, with Mut<...>, change) all of it. Its signature doesn't say what it needs, and a test has to build a whole Shop to call it. Taking the fields it reads says both, and the caller passes shop.state.cart.

❌ Rejected: the whole shop, for a cart and the rates

✕ Rejectedwide-param
ts
import type { Option } from "@evobug_com/safe-ts-std/result";

type Cart = { readonly weight: number };
type Rates = { readonly perKg: number };
type State = { readonly cart: Option<Cart>; readonly page: number };

interface Shop {
  readonly state: State;
  readonly rates: Rates;
  readonly title: string;
  readonly currency: string;
  readonly visits: number;
  readonly closed: boolean;
  readonly locale: string;
  readonly theme: string;
  readonly log: readonly string[];
  readonly errors: readonly string[];
  readonly started: number;
  readonly version: string;
}

export function shippingCost(shop: Shop, maxKg: number): number {
  if (!shop.state.cart) return 0;
  return Math.min(maxKg, shop.state.cart.weight) * shop.rates.perKg;
}

✅ Accepted: it takes what it reads

✓ Accepted0 diagnostics
ts
import type { Option } from "@evobug_com/safe-ts-std/result";

type Cart = { readonly weight: number };
type Rates = { readonly perKg: number };

export function shippingCost(cart: Option<Cart>, rates: Rates, maxKg: number): number {
  if (!cart) return 0;
  return Math.min(maxKg, cart.weight) * rates.perKg;
}

The message lists the paths, and the help their types (cart: Option<Cart>, perKg: number). Paths that start with the same field become the part they share: shop.state.cart and shop.state.page are shop.state.

What counts as wide. The parameter's type is a named interface, object type or class with at least 12 fields (its bases' fields included, across files) and no id field. A type with an id is a record of one thing, a product or an order: a function about a product takes the product, even when it reads only p.id today. Small types aren't reported either.

Not reported:

  • the parameter used as a whole anywhere in the function: passed on (render(shop)), returned, stored ({ shop }), spread, compared, destructured into a rest, or the receiver of a method call (shop.save()). Code that passes the context on reports nothing; the functions at the end of the chain, which read the fields, are the ones reported.
  • a field changed on the parameter itself (shop.closed = true): it can't be passed instead.
  • more than two separate paths.
  • a single field that is a wide context itself (shop.state alone, where State has 12 fields or more): taking it says no more about what the function needs.
  • signatures that come from elsewhere: functions and arrows written as arguments or with a typed variable, methods of classes that extend or implement something, methods of typed object literals, and functions handed on by name (every(100, poll), a JSX component).

✅ Accepted: the shop goes on to another function

✓ Accepted0 diagnostics
ts
import type { Option } from "@evobug_com/safe-ts-std/result";

type Cart = { readonly weight: number };
type Rates = { readonly perKg: number };
type State = { readonly cart: Option<Cart>; readonly page: number };

interface Shop {
  readonly state: State;
  readonly rates: Rates;
  readonly title: string;
  readonly currency: string;
  readonly visits: number;
  readonly closed: boolean;
  readonly locale: string;
  readonly theme: string;
  readonly log: readonly string[];
  readonly errors: readonly string[];
  readonly started: number;
  readonly version: string;
}

declare function renderPage(shop: Shop): void;

export function page(shop: Shop): void {
  if (shop.closed) return;
  renderPage(shop);
}

No quick fix: the callers change.

MIT OR Apache-2.0 · Docs by Gemini 4 Neon Extra