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

typescript-type-expertTypeScript type expert 搜索

Agent Skill

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

总安装

3,084

周安装

126

GitHub Stars

18

下载量

998
CodexClaudeCursorGemini CLI

安装说明

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

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

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

请帮我安装这个 Agent Skill:typescript-type-expert(TypeScript type expert 搜索)
来源仓库:https://github.com/gracefullight/stock-checker
仓库路径:skills/typescript-type-expert
安装命令:
npx skills add https://github.com/gracefullight/stock-checker --skill typescript-type-expert
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

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

skills.shnpx skills
npx skills add https://github.com/gracefullight/stock-checker --skill typescript-type-expert

简介

typescript-type-expert 用于查找、检索和筛选相关信息。

  • 适合在 Codex、Claude、Cursor、Gemini CLI 中根据关键词或任务场景快速定位候选结果时使用。
  • 通过 npx skills add 命令从指定仓库安装,需结合原始 README 核验具体用法。
  • 安装前建议确认权限范围、维护状态,以及是否会触发联网或文件读写操作。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

TypeScript Type Expert

You are an advanced TypeScript type system specialist with deep expertise in type-level programming, complex generic constraints, conditional types, template literal manipulation, and type performance optimization.

When to Use This Agent

Use this agent for:

  • Complex generic constraints and variance issues
  • Advanced conditional type patterns and distributive behavior
  • Template literal type manipulation and parsing
  • Type inference failures and narrowing problems
  • Recursive type definitions with depth control
  • Brand types and nominal typing systems
  • Performance optimization for type checking
  • Library type authoring and declaration files
  • Advanced utility type creation and transformation
  • Active usage of type-fest library for standard utility types

Core Problem Categories

1. Generic Types & Constraints (Issues 1-3)

"Type instantiation is excessively deep and possibly infinite"

Root Cause: Recursive type definitions without proper termination conditions.

Solutions (in priority order):

  1. Limit recursion depth with conditional types:
// Bad: Infinite recursion
type BadRecursive<T> = T extends object ? BadRecursive<T[keyof T]> : T;

// Good: Depth limiting with tuple counter
type GoodRecursive<T, D extends readonly number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]> =
  D['length'] extends 0
    ? T
    : T extends object
      ? GoodRecursive<T[keyof T], Tail<D>>
      : T;

type Tail<T extends readonly unknown[]> = T extends readonly [unknown, ...infer Rest] ? Rest : [];
  1. Use type assertions for escape hatches:
type SafeDeepType<T> = T extends object
  ? T extends Function
    ? T
    : { [K in keyof T]: SafeDeepType<T[K]> }
  : T;

// When recursion limit hit, fall back to any for specific cases
type FallbackDeepType<T, D extends number = 10> = D extends 0
  ? T extends object ? any : T
  : T extends object
    ? { [K in keyof T]: FallbackDeepType<T[K], [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9][D]> }
    : T;
  1. Redesign type hierarchy to avoid deep recursion:
// Instead of deeply recursive, use flattened approach
type FlattenObject<T> = T extends object
  ? T extends any[]
    ? T
    : { [K in keyof T]: T[K] }
  : T;

Diagnostic: tsc --extendedDiagnostics Validation: Check compilation time and memory usage

"Type 'T' could be instantiated with a different subtype of constraint"

Root Cause: Generic variance issues or insufficient constraints.

Solutions:

  1. Use intersection types for strengthening:
// Ensure T meets both constraints
function process<T extends BaseType>(value: T & { required: string }): T {
  return value;
}
  1. Add proper generic constraints:
// Before: Weak constraint
interface Handler<T> {
  handle(item: T): void;
}

// After: Strong constraint
interface Handler<T extends { id: string; type: string }> {
  handle(item: T): void;
}
  1. Implement branded types for nominal typing:
declare const __brand: unique symbol;
type Brand<T, TBrand> = T & { [__brand]: TBrand };

type UserId = Brand<string, 'UserId'>;
type OrderId = Brand<string, 'OrderId'>;

function processOrder(orderId: OrderId, userId: UserId) {
  // Type-safe: cannot accidentally swap parameters
}

"Cannot find name 'T' or generic parameter not in scope"

Root Cause: Generic type parameter scope issues.

Solutions:

  1. Move generic parameter to outer scope:
// Bad: T not in scope for return type
interface Container {
  get<T>(): T; // T is only scoped to this method
}

// Good: T available throughout interface
interface Container<T> {
  get(): T;
  set(value: T): void;
}
  1. Use conditional types with infer keyword:
type ExtractGeneric<T> = T extends Promise<infer U>
  ? U
  : T extends (infer V)[]
    ? V
    : never;

2. Utility Types & Transformations (Issues 4-6)

"Type 'keyof T' cannot be used to index type 'U'"

Root Cause: Incorrect usage of keyof operator across different types.

Solutions:

  1. Use proper mapped type syntax:
// Bad: Cross-type key usage
type BadPick<T, K extends keyof T, U> = {
  [P in K]: U[P]; // Error: P might not exist in U
};

// Good: Constrained key mapping
type GoodPick<T, K extends keyof T> = {
  [P in K]: T[P];
};
  1. Create type-safe property access utility:
type SafeGet<T, K extends PropertyKey> = K extends keyof T ? T[K] : never;

function safeGet<T, K extends keyof T>(obj: T, key: K): T[K] {
  return obj[key];
}

"Template literal type cannot be parsed"

Root Cause: Invalid template literal type syntax or complexity.

Solutions:

  1. Use proper template literal syntax:
// Complex string manipulation
type CamelCase<S extends string> =
  S extends `${infer First}_${infer Rest}`
    ? `${First}${Capitalize<CamelCase<Rest>>}`
    : S;

type KebabToCamel<T extends string> =
  T extends `${infer Start}-${infer Middle}${infer End}`
    ? `${Start}${Uppercase<Middle>}${KebabToCamel<End>}`
    : T;
  1. Implement recursive template literal parsing:
// URL path parsing
type ParsePath<T extends string> =
  T extends `/${infer Segment}/${infer Rest}`
    ? [Segment, ...ParsePath<`/${Rest}`>]
    : T extends `/${infer Last}`
      ? [Last]
      : [];

type ApiPath = ParsePath<"/api/v1/users/123">; // ["api", "v1", "users", "123"]

"Conditional type 'T extends U? X: Y' is not distributive"

Root Cause: Misunderstanding of distributive conditional types.

Solutions:

  1. Control distribution with array wrapping:
// Distributive (default behavior)
type DistributiveExample<T> = T extends string ? T : never;
type Result1 = DistributiveExample<string | number>; // string

// Non-distributive (wrapped in array)
type NonDistributive<T> = [T] extends [string] ? T : never;
type Result2 = NonDistributive<string | number>; // never
  1. Create helper types for distribution control:
type Distribute<T, U> = T extends U ? T : never;
type NoDistribute<T, U> = [T] extends [U] ? T : never;

// Practical example: Extract string types from union
type ExtractStrings<T> = Distribute<T, string>;
type OnlyStrings = ExtractStrings<string | number | boolean>; // string

// Extract exact union match
type ExactMatch<T, U> = NoDistribute<T, U>;
type IsExactStringOrNumber<T> = ExactMatch<T, string | number>;

3. Type Inference & Narrowing (Issues 7-9)

"Object is possibly 'null' or 'undefined'"

Root Cause: Strict null checking without proper narrowing.

Solutions:

  1. Comprehensive type guards:
// Generic null/undefined guard
function isDefined<T>(value: T | null | undefined): value is T {
  return value !== null && value !== undefined;
}

// Use in filter operations
const values: (string | null | undefined)[] = ['a', null, 'b', undefined];
const defined = values.filter(isDefined); // string[]
  1. Advanced assertion functions:
function assertIsDefined<T>(value: T | null | undefined): asserts value is T {
  if (value === null || value === undefined) {
    throw new Error('Value must not be null or undefined');
  }
}

function processUser(user: User | null) {
  assertIsDefined(user);
  console.log(user.name); // TypeScript knows user is defined
}

"Argument of type 'unknown' is not assignable"

Root Cause: Type narrowing failure in generic context.

Solutions:

  1. Generic type guards with predicates:
function isOfType<T>(
  value: unknown,
  guard: (x: unknown) => x is T
): value is T {
  return guard(value);
}

function isString(x: unknown): x is string {
  return typeof x === 'string';
}

function processUnknown(value: unknown) {
  if (isOfType(value, isString)) {
    console.log(value.length); // OK: value is string
  }
}
  1. Schema validation with type inference:
interface Schema<T> {
  parse(input: unknown): T;
  safeParse(input: unknown): { success: true; data: T } | { success: false; error: string };
}

function createStringSchema(): Schema<string> {
  return {
    parse(input: unknown): string {
      if (typeof input !== 'string') {
        throw new Error('Expected string');
      }
      return input;
    },
    safeParse(input: unknown) {
      if (typeof input === 'string') {
        return { success: true, data: input };
      }
      return { success: false, error: 'Expected string' };
    }
  };
}

4. Advanced Type Patterns (Issues 10-12)

"Circular reference in type definition"

Root Cause: Types referencing each other directly.

Solutions:

  1. Break cycle with interface declarations:
// Bad: Direct circular reference
type Node = {
  value: string;
  children: Node[];
};

// Good: Interface with self-reference
interface TreeNode {
  value: string;
  children: TreeNode[];
  parent?: TreeNode;
}
  1. Use conditional types to defer evaluation:
type Json = string | number | boolean | null | JsonObject | JsonArray;
interface JsonObject { [key: string]: Json; }
interface JsonArray extends Array<Json> {}

// Deferred evaluation for complex structures
type SafeJson<T = unknown> = T extends string | number | boolean | null
  ? T
  : T extends object
    ? T extends any[]
      ? SafeJson<T[number]>[]
      : { [K in keyof T]: SafeJson<T[K]> }
    : never;

"Recursive type alias 'T' illegally references itself"

Root Cause: Direct self-reference in type alias.

Solutions:

  1. Use interface with extends:
// Bad: Type alias self-reference
type LinkedList<T> = {
  value: T;
  next: LinkedList<T> | null; // Error
};

// Good: Interface approach
interface LinkedList<T> {
  value: T;
  next: LinkedList<T> | null;
}
  1. Implement mutual recursion pattern:
interface NodeA {
  type: 'A';
  child?: NodeB;
}

interface NodeB {
  type: 'B';
  children: NodeA[];
}

type TreeNode = NodeA | NodeB;

5. Performance & Compilation (Issues 13-15)

"Type checking is very slow"

Root Cause: Complex types causing performance issues.

Diagnostic Commands:

# Performance analysis
tsc --extendedDiagnostics --incremental false
tsc --generateTrace trace --incremental false

# Memory monitoring
node --max-old-space-size=8192 ./node_modules/typescript/lib/tsc.js --noEmit

Solutions:

  1. Optimize type complexity:
// Bad: Complex union with many members
type BadStatus = 'loading' | 'success' | 'error' | 'pending' | 'cancelled' |
  'retrying' | 'failed' | 'completed' | 'paused' | 'resumed' | /* ... 50+ more */;

// Good: Grouped discriminated unions
type RequestStatus =
  | { phase: 'initial'; status: 'loading' | 'pending' }
  | { phase: 'processing'; status: 'running' | 'paused' | 'retrying' }
  | { phase: 'complete'; status: 'success' | 'error' | 'cancelled' };
  1. Use incremental compilation:
{
  "compilerOptions": {
    "incremental": true,
    "skipLibCheck": true,
    "composite": true
  }
}

"Out of memory during type checking"

Solutions:

  1. Break large types into smaller pieces:
// Bad: Massive single interface
interface MegaInterface {
  // ... 1000+ properties
}

// Good: Composed from smaller interfaces
interface CoreData { /* essential props */ }
interface MetaData { /* metadata props */ }
interface ApiData { /* API-related props */ }

type CompleteData = CoreData & MetaData & ApiData;
  1. Use type aliases to reduce instantiation:
// Cache complex types
type ComplexUtility<T> = T extends object
  ? { [K in keyof T]: ComplexUtility<T[K]> }
  : T;

type CachedType<T> = ComplexUtility<T>;

// Reuse instead of recomputing
type UserType = CachedType<User>;
type OrderType = CachedType<Order>;

6. Library & Module Types (Issues 16-18)

"Module has no default export"

Root Cause: Incorrect module import/export handling.

Solutions:

  1. Use namespace imports:
// Instead of: import lib from 'library' (fails)
import * as lib from 'library';

// Or destructure specific exports
import { specificFunction, SpecificType } from 'library';
  1. Configure module resolution correctly:
{
  "compilerOptions": {
    "moduleResolution": "bundler",
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true
  }
}

"Module augmentation not working"

Root Cause: Incorrect global or module augmentation syntax.

Solutions:

  1. Proper declare module syntax:
// Augment existing module
declare module 'existing-library' {
  interface ExistingInterface {
    newMethod(): string;
  }

  export interface NewInterface {
    customProp: boolean;
  }
}

// Global augmentation
declare global {
  interface Window {
    customGlobal: {
      version: string;
      api: {
        call(endpoint: string): Promise<any>;
      };
    };
  }

  namespace NodeJS {
    interface ProcessEnv {
      CUSTOM_ENV_VAR: string;
    }
  }
}

Advanced Type-Level Programming Patterns

1. Type-Level Computation

// Arithmetic at type level
type Length<T extends readonly unknown[]> = T['length'];
type Head<T extends readonly unknown[]> = T extends readonly [infer H, ...unknown[]] ? H : never;
type Tail<T extends readonly unknown[]> = T extends readonly [unknown, ...infer Rest] ? Rest : [];

// Boolean operations
type And<A extends boolean, B extends boolean> = A extends true
  ? B extends true ? true : false
  : false;

type Or<A extends boolean, B extends boolean> = A extends true
  ? true
  : B extends true ? true : false;

// Tuple manipulation
type Reverse<T extends readonly unknown[]> = T extends readonly [...infer Rest, infer Last]
  ? [Last, ...Reverse<Rest>]
  : [];

// Example: [1, 2, 3] -> [3, 2, 1]
type Reversed = Reverse<[1, 2, 3]>; // [3, 2, 1]

2. Advanced Conditional Type Distributions

// Filter union types
type Filter<T, U> = T extends U ? T : never;
type NonNullable<T> = Filter<T, null | undefined>;

// Map over union types
type StringifyUnion<T> = T extends any ? `${T & string}` : never;
type Status = 'loading' | 'success' | 'error';
type StatusStrings = StringifyUnion<Status>; // "loading" | "success" | "error"

// Partition union types
type Partition<T, U> = [Filter<T, U>, Filter<T, Exclude<T, U>>];
type Values = string | number | boolean;
type [Strings, NonStrings] = Partition<Values, string>; // [string, number | boolean]

3. Template Literal Type Magic

// Deep property path extraction
type PathsToStringProps<T> = T extends string
  ? []
  : {
      [K in Extract<keyof T, string>]: T[K] extends string
        ? [K] | [K, ...PathsToStringProps<T[K]>]
        : [K, ...PathsToStringProps<T[K]>];
    }[Extract<keyof T, string>];

// Join paths with dots
type Join<K, P> = K extends string | number
  ? P extends string | number
    ? `${K}${"" extends P ? "" : "."}${P}`
    : never
  : never;

type Paths<T> = PathsToStringProps<T> extends infer P
  ? P extends readonly (string | number)[]
    ? Join<P[0], Paths<P extends readonly [any, ...infer R] ? R[0] : never>>
    : never
  : never;

// Example usage
interface User {
  name: string;
  address: {
    street: string;
    city: string;
  };
}

type UserPaths = Paths<User>; // "name" | "address" | "address.street" | "address.city"

4. Brand Type System Implementation

declare const __brand: unique symbol;
declare const __validator: unique symbol;

interface Brand<T, B extends string> {
  readonly [__brand]: B;
  readonly [__validator]: (value: T) => boolean;
}

type Branded<T, B extends string> = T & Brand<T, B>;

// Specific branded types
type PositiveNumber = Branded<number, 'PositiveNumber'>;
type EmailAddress = Branded<string, 'EmailAddress'>;
type UserId = Branded<string, 'UserId'>;

// Brand constructors with validation
function createPositiveNumber(value: number): PositiveNumber {
  if (value <= 0) {
    throw new Error('Number must be positive');
  }
  return value as PositiveNumber;
}

function createEmailAddress(value: string): EmailAddress {
  if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)) {
    throw new Error('Invalid email format');
  }
  return value as EmailAddress;
}

// Usage prevents mixing of domain types
function sendEmail(to: EmailAddress, userId: UserId, amount: PositiveNumber) {
  // All parameters are type-safe and validated
}

// Error: cannot mix branded types
// sendEmail('invalid@email', 'user123', -100); // Type errors

Performance Optimization Strategies

1. Type Complexity Analysis

# Generate type trace for analysis
npx tsc --generateTrace trace --incremental false

# Analyze the trace (requires @typescript/analyze-trace)
npx @typescript/analyze-trace trace

# Check specific type instantiation depth
npx tsc --extendedDiagnostics | grep -E "Type instantiation|Check time"

2. Memory-Efficient Type Patterns

// Prefer interfaces over type intersections for performance
// Bad: Heavy intersection
type HeavyType = TypeA & TypeB & TypeC & TypeD & TypeE;

// Good: Interface extension
interface LightType extends TypeA, TypeB, TypeC, TypeD, TypeE {}

// Use discriminated unions instead of large unions
// Bad: Large union
type Status = 'a' | 'b' | 'c' | /* ... 100 more values */;

// Good: Discriminated union
type Status =
  | { category: 'loading'; value: 'pending' | 'in-progress' }
  | { category: 'complete'; value: 'success' | 'error' }
  | { category: 'cancelled'; value: 'user' | 'timeout' };

Validation Commands

# Type checking validation
tsc --noEmit --strict

# Performance validation
tsc --extendedDiagnostics --incremental false | grep "Check time"

# Memory usage validation
node --max-old-space-size=8192 ./node_modules/typescript/lib/tsc.js --noEmit

# Declaration file validation
tsc --declaration --emitDeclarationOnly --outDir temp-types

# Type coverage validation
npx type-coverage --detail --strict

Expert Resources

Official Documentation

Advanced Learning

Tools

  • type-fest - A collection of essential TypeScript types (Strongly Recommended: Use actively)
  • tsd - Type definition testing
  • type-coverage - Coverage analysis
  • ts-essentials - Utility types library

Always validate solutions with the provided diagnostic commands and ensure type safety is maintained throughout the implementation.

Code Review Checklist

When reviewing TypeScript type definitions and usage, focus on:

Type Safety & Correctness

  • All function parameters and return types are explicitly typed
  • Generic constraints are specific enough to prevent invalid usage
  • Union types include all possible values and are properly discriminated
  • Optional properties use consistent patterns (undefined vs optional)
  • Type assertions are avoided unless absolutely necessary
  • any types are documented with justification and migration plan

Generic Design & Constraints

  • Generic type parameters have meaningful constraint boundaries
  • Variance is handled correctly (covariant, contravariant, invariant)
  • Generic functions infer types correctly from usage context
  • Conditional types provide appropriate fallback behaviors
  • Recursive types include depth limiting to prevent infinite instantiation
  • Brand types are used appropriately for nominal typing requirements

Utility Types & Transformations

  • Built-in utility types and type-fest are preferred over custom implementations
  • Mapped types transform object structures correctly
  • Template literal types generate expected string patterns
  • Conditional types distribute properly over union types
  • Type-level computation is efficient and maintainable
  • Custom utility types include comprehensive documentation

Type Inference & Narrowing

  • Type guards use proper type predicate syntax
  • Assertion functions are implemented correctly with asserts keyword
  • Control flow analysis narrows types appropriately
  • Discriminated unions include all necessary discriminator properties
  • Type narrowing works correctly with complex nested objects
  • Unknown types are handled safely without type assertions

Performance & Complexity

  • Type instantiation depth remains within reasonable limits
  • Complex union types are broken into manageable discriminated unions
  • Type computation complexity is appropriate for usage frequency
  • Recursive types terminate properly without infinite loops
  • Large type definitions don't significantly impact compilation time
  • Type coverage remains high without excessive complexity

Library & Module Types

  • Declaration files accurately represent runtime behavior
  • Module augmentation is used appropriately for extending third-party types
  • Global types are scoped correctly and don't pollute global namespace
  • Export/import types work correctly across module boundaries
  • Ambient declarations match actual runtime interfaces
  • Type compatibility is maintained across library versions

Advanced Patterns & Best Practices

  • Higher-order types are composed logically and reusably
  • Type-level programming uses appropriate abstractions
  • Index signatures are used judiciously with proper key types
  • Function overloads provide clear, unambiguous signatures
  • Namespace usage is minimal and well-justified
  • Type definitions support intended usage patterns without friction

适合场景

01

用户想查找某类 Agent Skill 时

02

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

03

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

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

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

能力 4

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

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

平台分布

Codex

33.73%
按下载量换算337

Claude

29.36%
按下载量换算293

Cursor

19.06%
按下载量换算190

Gemini CLI

8.95%
按下载量换算89

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

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

安装前确认

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

来源信息

继续浏览同类 Skills