variadic-tuple-types
Use Rest Parameters and Tuple Types to Model Variadic Functions
Overview
Variadic functions - functions that accept a variable number of arguments - are common in JavaScript. TypeScript's tuple types and rest parameters let you type these precisely, preserving the number and types of arguments. This enables powerful patterns like typed function composition and generic pipelines.
Understanding how to combine rest parameters with tuple types unlocks precise typing for flexible APIs.
When to Use This Skill
- Functions accept variable number of typed arguments
- Need to preserve tuple length through transformations
- Building generic function composition utilities
- Typing rest parameters with specific constraints
- Creating typed function pipelines
The Iron Rule
Use rest parameters with tuple types to precisely type variadic functions. Combine with generics to preserve argument types through transformations.
More from marius-townhouse/effective-typescript-skills
precise-any-variants
Use when forced to use any. Use when any is too broad. Use when function types need any.
86narrow-any-scope
Use when any is unavoidable. Use when working with untyped libraries. Use when silencing specific type errors.
35tsdoc-comments
Use when documenting public APIs. Use when writing library code. Use when using JSDoc-style comments. Use when generating documentation. Use when explaining complex types.
34exhaustiveness-checking
Use when handling tagged unions. Use when adding new cases to discriminated unions. Use when switch statements must cover all cases.
13code-gen-independent
Use when confused about types at runtime. Use when trying to use instanceof with interfaces. Use when type errors don't prevent JavaScript output.
12tsconfig-options
Use when setting up a TypeScript project. Use when confused by type checking behavior. Use when strict mode causes unexpected errors.
11