typescript-conventions
Installation
SKILL.md
TypeScript coding conventions
- Apply the active file's repository documentation, AGENTS.md, lint rules, and configuration first. Use this guidance for TypeScript, including embedded TypeScript, and combine available framework, testing, or library skills when needed.
- Use Valibot for runtime validation schemas, following the project's schema organization and reusing existing contracts where applicable.
Avoid return undefined
Do not use return undefined. When exiting a function without a value, use a bare return.
Extract non-trivial intermediate computations
- Before embedding a non-trivial computation in an argument, property value, array element, condition, loop input, spread source, return value, or larger expression, assign it to a named
constorlet. - Give ordinary nested calls, awaited values, constructors, chained transforms, template-built values, ternaries, and multi-operator expressions meaningful intermediate names before another computation consumes them.
- Exception: keep immediately clear elementary expressions inline, including property or element access, optional chaining,
??, unary checks, simple comparisons, and one-step arithmetic. Do not split them solely to satisfy this rule. An initializer that already gives its result a meaningful name may contain a clear calculation. - Arrange dependent statements in execution order: resolve input, transform it, then consume the result.
- Keep nested or chained calls in declarative library APIs (embedded DSLs) when their structure expresses a declaration, such as a schema, query, or rule set. Follow the API's established composition style. Extract ordinary data preparation used as input; for example, name the result of
parseId(rawId)before using it insideeq(users.id, id). A chain of data transformations follows the ordinary extraction rule. - Preserve behavior and algorithmic complexity; do not add intermediate collections or passes solely for formatting.