Awesome Reviewers

Reviewer · API

Design extensible API interfaces

When designing function signatures or data contracts that are public, growing, or likely to evolve, favor explicit, structured, and forward-compatible shapes over ad-hoc positional parameters or implicit conventions.

Instruction

When designing function signatures or data contracts that are public, growing, or likely to evolve, favor explicit, structured, and forward-compatible shapes over ad-hoc positional parameters or implicit conventions.

  • Prefer named options objects over multiple positional or boolean parameters once a function’s argument list starts growing or mixes unrelated concerns (e.g. mode selection vs. behavior configuration). This avoids ambiguous call sites like fn(true, false, 'x') and makes call sites self-documenting. It’s especially important for public-facing APIs/tools that define schemas keyed by argument name (e.g. getComponentByUid({ uid, includeHooks }) instead of getComponentByUid(uid, includeHooks)).
  • When a public type is introduced, mark fields optional if there’s any chance they won’t always be populated, so future call sites that omit the field don’t require a breaking change.
  • Avoid relying on an implicit, undocumented shape of opaque data (e.g. indexing into an array assuming [id, chunks, name]) when that data crosses an API boundary such as a host config. Instead, expose an explicit method/hook (e.g. getClientReferenceMetadataChunks) so the contract is enforced by the type system rather than by convention.
  • When a factory function accumulates many parameters that serve different purposes (opting into a mode vs. configuring behavior within that mode), consider splitting it into mode-specific constructors or grouping related parameters into nested config objects, keeping hot-path/frequently-read structures flat for performance while allowing more structure in rarely-created configuration objects.

Example — prefer an options object for multi-parameter or public-facing functions:

// Avoid
getComponentByUid(uid, true, false);

// Prefer
getComponentByUid({ uid, includeHooks: true, includeSource: false });