rea-analysis-optimization
MOmorluto/rea485k7,690 new stars in the last 7 days
Apply, review, and explain TypeScript function conventions. Use automatically for tasks involving function responsibility, statelessness, purity, side effects, function arguments, function API design, or return types.
Apply the TypeScript Style Guide's function conventions in the context of the current task.
For detailed guidance on mutually exclusive function arguments, use typescript-discriminated-unions when it is available.
Function conventions should be followed as much as possible (some derive from basic functional programming concepts):
Prefer functions that:
A stateless function does not retain data between calls. A deterministic function returns the same result for the same inputs. A pure function is deterministic and has no observable side effects, making it easier to understand, test, and reuse.
Not every function can be pure. Network requests, storage, logging, and UI updates require side effects. Keep these functions small and isolate side effects from pure business logic.
When a function accepts several related parameters, prefer a single object parameter. Named properties make call sites easier to understand and allow the function API to evolve without relying on argument order.
Keep positional parameters when their meaning and order are obvious, or when a conventional signature is clearer, such as isNumber(value) or a callback.
// ❌ Multiple arguments make this call difficult to understand
transformUserInput('client', false, 60, 120, null, true, 2000);
// ✅ An object makes each argument explicit
transformUserInput({
method: 'client',
isValidated: false,
minLines: 60,
maxLines: 120,
defaultInput: null,
shouldLog: true,
timeout: 2000,
});
Strive to have the majority of arguments required and use optional arguments sparingly.
If the function becomes too complex, it probably should be broken into smaller pieces.
An exaggerated example: implementing 10 focused functions with 5 required arguments each is preferable to implementing one "do-it-all" function with 50 optional arguments.
When function arguments represent mutually exclusive cases, use discriminated unions.
Requiring explicit return types improves safety, catches errors early, and helps with long-term maintainability. However, excessive strictness can slow development and add unnecessary redundancy.
As a rule of thumb, be explicit on the outside, implicit on the inside. For example, when building APIs or libraries, always type everything explicitly to avoid accidental breaking changes. For internal logic, let TypeScript infer its defaults, which will provide strong type safety without added verbosity.
Consider the advantages of explicitly defining the return type of a function:
As context matters, use explicit return types when they add clarity and safety.
<Rule prefix="Require explicit return types at module boundaries" href="https://typescript-eslint.io/rules/explicit-module-boundary-types/"
{
"@typescript-eslint/explicit-module-boundary-types": "error"}
MOmorluto/rea485k7,690 new stars in the last 7 days
MAmattpocock/skills336k4,217 new stars in the last 7 days
Diagnose hard bugs and performance regressions by building a feedback loop with tests or scripts.
MAmattpocock/skills336k4,217 new stars in the last 7 days
MAmattpocock/skills336k4,217 new stars in the last 7 days
MAmattpocock/skills336k4,217 new stars in the last 7 days
MAmattpocock/skills336k4,217 new stars in the last 7 days