skills/reduce-optional-params/SKILL.md
Use when designing or refactoring functions with many optional params, configurable components, or when the user mentions optional params, function signatures, or API simplification. Reduces optional parameters in functions and components for cleaner APIs.
npx skillsauth add tianyili/skills reduce-optional-paramsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Guidance for simplifying function and component signatures by reducing optional parameters. Too many optional params make call sites hard to read and APIs fragile.
Before adding an optional param, ask: (1) Is there a concrete use case? (2) Would a separate function or preset make intent clearer? (3) Would callers pass this only in a few places? (If yes, a dedicated function or preset may be clearer.)
Group related optional params into a single config object.
// Before
function fetchUser(id: string, includeProfile?: boolean, cache?: boolean, timeout?: number) {}
// After
function fetchUser(id: string, options?: { includeProfile?: boolean; cache?: boolean; timeout?: number }) {}
Use when: Params are loosely related and callers typically pass 0–2 at a time.
Edge case: If one option is required in most call sites, keep it as a required positional param and put the rest in the options object (e.g. fetchUser(id, { includeProfile: true })).
Replace one function with many optional params with smaller, purpose-specific functions.
// Before
function createButton(text: string, variant?: string, size?: string, disabled?: boolean, icon?: string) {}
// After
function createPrimaryButton(text: string, opts?: { size?: string }) {}
function createIconButton(text: string, icon: string, opts?: { size?: string }) {}
Use when: Optional params create distinct usage modes (e.g. "icon mode" vs "text-only").
Use children, compound components, or render props instead of optional props.
// Before
<Button text="Save" variant="primary" size="md" leftIcon={<SaveIcon />} rightIcon={null} loading={false} />
// After
<Button variant="primary" size="md">
<Button.Icon><SaveIcon /></Button.Icon>
Save
</Button>
Use when: UI has many configurable facets that rarely combine.
Expose presets for common configurations instead of one function with many options.
// Before
function connect(url: string, retries?: number, timeout?: number, ssl?: boolean) {}
// After
function connect(url: string, opts?: ConnectionOptions) {}
function connectProduction(url: string) {
return connect(url, { retries: 3, timeout: 5000, ssl: true });
}
Use when: A few well-defined configurations dominate usage.
Move "optional" params into a narrower function where they become required.
// Before
function render(component: Component, layout?: string, theme?: string) {}
// After
function render(component: Component) {}
function renderWithLayout(component: Component, layout: string, theme?: string) {}
Use when: Some params are optional only in the generic path but required in specific paths.
Use a builder when callers need to set many options and discoverability helps.
// Before
createModal(title: string, content: string, closable?: boolean, width?: number, onClose?: () => void) {}
// After
Modal.create(title, content).closable(true).width(400).onClose(handler).show()
Use when: 5+ options and fluent-style API is acceptable in the codebase.
development
Use and structure Zustand stores for React and vanilla JS state management. Use when the user mentions Zustand, needs a store pattern, global state, persist state, or migrating from Redux/Context.
tools
Use when displaying token balances or token values in UI, converting user input to bigint for contract writes, or doing math with wei/token amounts in viem or wagmi apps. Web3 number formatting with formatUnits, parseUnits, BigNumber, bigint naming (`Raw`, `Formatted`, `Bn`), decimals handling, and reusable display helpers. Triggers on token balance, formatUnits, parseUnits, wei, decimals, bigint, BigNumber, number formatting, or web3 display math.
development
React performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React code to ensure optimal performance patterns. Triggers on tasks involving React components, data fetching, bundle optimization, or performance improvements.
development
Implements data tables using @tanstack/react-table v8 with project UI primitives. Use when adding or modifying tables, column configs, sorting, filtering, row selection, or virtualized table bodies.