Function Standards
Overview
Patterns for writing functions in TypeScript. This standard covers parameter design, documentation, purity, and composition. Well-structured functions are the primary unit of abstraction in this codebase and should be small, focused, and composable.
Rules
Use Object Parameters
Use an object parameter when a function has 2 or more related parameters, especially when those parameters are primitives where the meaning is unclear at the call site.
Define an interface with a Params, Options, or Args suffix, then destructure in the function signature.
Correct
Incorrect
Document All Functions with JSDoc
Every function requires a JSDoc comment — both exported and non-exported. Document the "why" more than the "what". For object parameters, document the object as a whole rather than listing every property.
Exported functions get a full JSDoc block with @param and @returns tags.
Non-exported (private) functions get a JSDoc block with the @private tag. Keep the description concise — one line is enough for simple helpers.
Test files are exempt from this rule.
Correct
Incorrect
Prefer Pure Functions
Prefer pure functions that have no side effects and return predictable outputs. Same inputs must always produce same outputs, with no modification of external state and no I/O operations.
Correct
Incorrect
Compose Small Functions
Prefer small, focused functions that can be composed together. Use early returns to flatten control flow instead of nesting.
Correct
Incorrect
References
- Naming Conventions -- Parameter interface naming
- Design Patterns -- Factories, pipelines, composition