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

function-type-expressions函数类型表达式

Agent Skill

function-type-expressions 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

208

周安装

8

GitHub Stars

2

下载量

65
CodexClaudeCursorGemini CLI

安装说明

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

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

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

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

命令行安装

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

skills.shnpx skills
npx skills add https://github.com/marius-townhouse/effective-typescript-skills --skill function-type-expressions

简介

function-type-expressions 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中根据关键词、任务场景或来源线索快速定位候选结果。

  • 它可结合来源仓库、安装命令和原始 README 继续核验具体用法。
  • 安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。
  • 当前顶部介绍已提供,底部简介为空,原始 SKILL.md 摘录缺失。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

Apply Types to Entire Function Expressions When Possible

Overview

Type entire functions at once instead of individual parameters.

When using function expressions (not statements), you can apply a type to the entire function. This reduces repetition, improves type safety, and makes code more readable.

When to Use This Skill

  • Writing multiple functions with the same signature
  • Implementing callbacks for libraries
  • Matching signatures of existing functions
  • Wrapping or extending existing functions

The Iron Rule

When functions share a signature, define the type ONCE and apply it to EACH function.

Remember:

  • Function expressions can have types applied to them
  • Parameter types are inferred from the function type
  • Return types are checked against the function type
  • Use typeof fn to match existing function signatures

Detection: Repeated Signatures

// Repetitive - same signature 4 times
function add(a: number, b: number) { return a + b; }
function sub(a: number, b: number) { return a - b; }
function mul(a: number, b: number) { return a * b; }
function div(a: number, b: number) { return a / b; }

The Solution: Function Types

Define Once, Use Many Times

type BinaryFn = (a: number, b: number) => number;

const add: BinaryFn = (a, b) => a + b;  // Types inferred
const sub: BinaryFn = (a, b) => a - b;
const mul: BinaryFn = (a, b) => a * b;
const div: BinaryFn = (a, b) => a / b;

Benefits:

  • No repeated type annotations
  • Return type checked automatically
  • Logic is more visible without type noise

Match Existing Functions with typeof

// Match fetch's signature exactly
const checkedFetch: typeof fetch = async (input, init) => {
  const response = await fetch(input, init);
  if (!response.ok) {
    throw new Error(`Request failed: ${response.status}`);
  }
  return response;
};

TypeScript infers:

  • input: RequestInfo | URL
  • init?: RequestInit
  • Return: Promise<Response>

Change Return Type with Parameters

// Match parameters but change return type
async function fetchNumber(
  ...args: Parameters<typeof fetch>
): Promise<number> {
  const response = await checkedFetch(...args);
  return Number(await response.text());
}

Function Statement vs Expression

// Statement - must annotate each parameter
function rollDice1(sides: number): number { /* ... */ }

// Expression - can apply type to entire function
type DiceRollFn = (sides: number) => number;
const rollDice2: DiceRollFn = (sides) => { /* ... */ };

Common Function Type Patterns

Callback Types

type EventHandler = (event: Event) => void;
type AsyncCallback<T> = () => Promise<T>;
type Comparator<T> = (a: T, b: T) => number;

const handleClick: EventHandler = (e) => {
  console.log(e.target);  // e is typed as Event
};

Generic Function Types

type Mapper<T, U> = (item: T, index: number) => U;

const double: Mapper<number, number> = (n) => n * 2;
const stringify: Mapper<number, string> = (n) => String(n);

Interface Syntax (Alternative)

// Function type as interface
interface StringTransform {
  (input: string): string;
}

const toUpper: StringTransform = s => s.toUpperCase();

Return Type Safety

Function types catch return type errors:

const checkedFetch: typeof fetch = async (input, init) => {
  const response = await fetch(input, init);
  if (!response.ok) {
    return new Error('Failed');  // Error!
    // Type 'Error' is not assignable to type 'Response'
  }
  return response;
};

Without the function type, this would only error at call sites.

Library Callback Types

Libraries often provide callback types:

// React provides these
import { MouseEventHandler, ChangeEventHandler } from 'react';

const handleClick: MouseEventHandler<HTMLButtonElement> = (e) => {
  console.log(e.currentTarget.disabled);  // Fully typed
};

const handleChange: ChangeEventHandler<HTMLInputElement> = (e) => {
  console.log(e.target.value);  // Fully typed
};

When NOT to Use Function Types

Don't over-engineer for single functions:

// Overkill for a single standalone function
type GreetFn = (name: string) => string;
const greet: GreetFn = (name) => `Hello, ${name}`;

// Just use a normal function statement
function greet(name: string): string {
  return `Hello, ${name}`;
}

Pressure Resistance Protocol

1. "Function Statements Are Clearer"

Pressure: "I prefer seeing types inline with parameters"

Response: With shared signatures, centralizing the type removes noise.

Action: Use function types when 2+ functions share a signature.

2. "I Don't Know the Library's Type"

Pressure: "I can't find the callback type in the library"

Response: Use typeof existingFunction or Parameters<typeof fn>.

Action: Match existing signatures with typeof.

Red Flags - STOP and Reconsider

  • Same parameter types repeated across multiple functions
  • Wrapper functions that should match the wrapped function's signature
  • Callbacks without proper typing

Common Rationalizations (All Invalid)

ExcuseReality
"Types on parameters are clearer"Not when repeated 4 times
"Function statements are simpler"Function expressions with types are just as clear
"I'll just use any"Loses all type safety benefits

Quick Reference

// Define function type
type Transform<T> = (value: T) => T;

// Apply to function expression
const double: Transform<number> = v => v * 2;

// Match existing function
const myFetch: typeof fetch = async (input, init) => { ... };

// Match parameters, change return
function wrapper(...args: Parameters<typeof original>): NewReturn { ... }

The Bottom Line

Apply types to entire function expressions when you have shared signatures.

This reduces repetition, centralizes type definitions, and catches return type errors at the source. Use typeof to match existing function signatures exactly.

Reference

Based on "Effective TypeScript" by Dan Vanderkam, Item 12: Apply Types to Entire Function Expressions When Possible.

适合场景

01

用户想查找某类 Agent Skill 时

02

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

03

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

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

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

能力 4

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

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

平台分布

Codex

38.85%
按下载量换算25

Claude

29.73%
按下载量换算19

Cursor

19.27%
按下载量换算13

Gemini CLI

8.81%
按下载量换算6

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

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

安装前确认

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

来源信息

继续浏览同类 Skills