Token导航 LogoToken导航TokenDH.com
开发需要联网github未标认证来源可访问许可证需确认审计通过

variadic-tuple-types可变元组类型

Agent Skill

variadic-tuple-types 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

198

周安装

8

GitHub Stars

2

下载量

62
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:variadic-tuple-types(可变元组类型)
来源仓库:https://github.com/marius-townhouse/effective-typescript-skills
仓库路径:skills/variadic-tuple-types
安装命令:
npx skills add https://github.com/marius-townhouse/effective-typescript-skills --skill variadic-tuple-types
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/marius-townhouse/effective-typescript-skills --skill variadic-tuple-types

简介

variadic-tuple-types 用于处理 GitHub 仓库、Issue 和 Pull Request 协作信息。

  • 它适合围绕代码变更、仓库状态或协作事项进行整理。
  • 通过 npx skills add 命令从指定 GitHub 仓库安装并使用。
  • 安装前建议确认权限范围和是否会触发文件读写操作。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

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.

Detection

Watch for these untyped patterns:

// RED FLAGS - Untyped variadic functions
function logAll(...args: any[]): void;  // Lost type information
function compose(...fns: Function[]): Function;  // No type safety
function curry(fn: Function): Function;  // Arguments not tracked

Basic Rest Parameters with Tuples

// Preserve exact argument types
function logAll<T extends any[]>(...args: T): void {
  console.log(args);
}

logAll(1, 'hello', true);
// T is inferred as [number, string, boolean]

// Constrain the tuple
type StringNumberPair = [string, number];
function formatPair(...pair: StringNumberPair): string {
  return `${pair[0]}: ${pair[1]}`;
}

formatPair('score', 100);  // OK
formatPair('score');       // Error: missing number
formatPair('score', 100, 'extra');  // Error: too many arguments

Generic Variadic Functions

// Preserve types through transformation
function tail<T extends any[]>(
  head: T[0],
  ...rest: T extends [any, ...infer R] ? R : never
): T {
  return [head, ...rest] as T;
}

const result = tail(1, 'a', true);
// result: [number, string, boolean]

Function Composition

// Compose functions with preserved types
type Fn = (...args: any[]) => any;

function compose<T extends Fn[]>(
  ...fns: T
): (...args: Parameters<T[0]>) => ReturnType<T[number]> {
  return (arg) => fns.reduceRight((acc, fn) => fn(acc), arg);
}

const add1 = (x: number) => x + 1;
const double = (x: number) => x * 2;
const toString = (x: number) => String(x);

const composed = compose(toString, double, add1);
// (x: number) => string

const result = composed(5);  // "12"

Curry with Tuple Types

// Type-safe currying
type Curry<T extends any[], R> = T extends [infer First, ...infer Rest]
  ? (arg: First) => Rest extends [] ? R : Curry<Rest, R>
  : () => R;

function curry<T extends any[], R>(
  fn: (...args: T) => R
): Curry<T, R> {
  return ((arg: any) => {
    if (arguments.length >= fn.length) {
      return fn(...arguments);
    }
    return curry(fn.bind(null, arg));
  }) as Curry<T, R>;
}

const sum3 = (a: number, b: number, c: number) => a + b + c;
const curried = curry(sum3);

const result = curried(1)(2)(3);  // 6
// Each step is correctly typed!

Real-World Example: Event Emitter

type EventMap = {
  click: [x: number, y: number];
  keypress: [key: string];
  load: [];
};

class TypedEmitter<Events extends Record<string, any[]>> {
  emit<K extends keyof Events>(
    event: K,
    ...args: Events[K]
  ): void {
    // Implementation
  }

  on<K extends keyof Events>(
    event: K,
    handler: (...args: Events[K]) => void
  ): void {
    // Implementation
  }
}

const emitter = new TypedEmitter<EventMap>();

emitter.emit('click', 100, 200);  // OK
emitter.emit('click', 100);       // Error: missing y
emitter.on('keypress', (key) => {
  console.log(key);  // key is string
});

Pressure Resistance Protocol

When typing variadic functions:

  1. Use tuple constraints: [string, number] not string | number
  2. Preserve with generics: T extends any[] captures exact types
  3. Consider length: Use tuple length for conditional types
  4. Test edge cases: Empty tuples, single elements, many elements

Red Flags

Anti-PatternProblemSolution
...args: any[]Lost type informationT extends any[]
Function typeNo parameter/return typesGeneric function types
Array instead of tupleLoses length informationTuple types

Common Rationalizations

"It's too complex for my use case"

Reality: Start with T extends any[] and add complexity only when needed.

"Users can pass arguments as an array"

Reality: Rest parameters are more ergonomic. Type them correctly for best DX.

"I'll just use overloads"

Reality: Tuples handle the general case. Overloads require manual enumeration.

Quick Reference

PatternSyntaxUse Case
Capture argsT extends any[]Preserve argument types
Constrain length[A, B, C]Fixed number of args
Minimum length[A, B,...C[]]At least 2 args
TransformParameters<T[0]>Extract parameter types

The Bottom Line

Rest parameters with tuple types enable precise typing of variadic functions. Use generics to preserve argument types through transformations, enabling powerful patterns like typed composition.

Reference

  • Effective TypeScript, 2nd Edition by Dan Vanderkam
  • Item 62: Use Rest Parameters and Tuple Types to Model Variadic Functions

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

35.24%
按下载量换算22

Claude

29.2%
按下载量换算18

Cursor

19.6%
按下载量换算12

Gemini CLI

9.88%
按下载量换算6

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills