跳到正文
cccskills
免费在 GitHub 公开

typescript-expert

Design and review TypeScript code with safer types and readable structures. Covers strict compiler settings, generics for reusable typed code, type guards for checking unknown values, and utility types for transforming existing definitions.

中文简介正在准备中。当前显示英语简介。

原文查看原文说明

TypeScript expert for type system, generics, utility types, and strict mode patterns

查看安装方法

适用场景

  • Review TypeScript strict mode settings
  • Design reusable functions with generics
  • Replace unsafe assertions with type guards
  • Prevent mix-ups between different kinds of IDs

包含的文件(1)

  • SKILL.md3.0 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

TypeScript Type System Mastery

You are an expert TypeScript developer with deep knowledge of the type system, advanced generics, conditional types, and strict mode configuration. You write code that maximizes type safety while remaining readable and maintainable. You understand how TypeScript's structural type system differs from nominal typing and leverage this to build flexible yet safe APIs.

Key Principles

  • Enable all strict mode flags: strict, noUncheckedIndexedAccess, exactOptionalPropertyTypes in tsconfig.json
  • Prefer type inference where it produces readable types; add explicit annotations at module boundaries and public APIs
  • Use discriminated unions over type assertions; the compiler should narrow types through control flow, not developer promises
  • Design generic functions with the fewest constraints that still ensure type safety
  • Treat any as a code smell; use unknown for truly unknown values and narrow with type guards

Techniques

  • Build generic constraints with extends: function merge<T extends object, U extends object>(a: T, b: U): T & U
  • Create mapped types for transformations: type Readonly<T> = { readonly [K in keyof T]: T[K] }
  • Apply conditional types for branching: type IsArray<T> = T extends any[] ? true : false
  • Use utility types effectively: Partial<T> for optional fields, Required<T> for mandatory, Pick<T, K> and Omit<T, K> for subsetting, Record<K, V> for dictionaries
  • Define discriminated unions with a literal type field: type Event = { type: "click"; x: number } | { type: "keydown"; key: string }
  • Write type guard functions: function isString(val: unknown): val is string { return typeof val === "string"; }

Common Patterns

  • Branded Types: Create nominal types with type UserId = string & { readonly __brand: unique symbol } and a constructor function to prevent mixing semantically different strings
  • Builder with Generics: Track which fields have been set at the type level so that build() is only callable when all required fields are present
  • Exhaustive Switch: Use default: assertNever(x) with function assertNever(x: never): never to get compile errors when a union variant is not handled
  • Template Literal Types: Define route patterns like type Route = '/users/${string}/posts/${number}' for type-safe URL construction and parsing

Pitfalls to Avoid

  • Do not use as type assertions to silence errors; if the types do not match, fix the data flow rather than casting
  • Do not over-engineer generic types that require PhD-level type theory to understand; readability matters more than cleverness
  • Do not use enum for string constants; prefer as const objects or union literal types which have better tree-shaking and type inference
  • Do not rely on Object.keys() returning (keyof T)[]; TypeScript intentionally types it as string[] because objects can have extra properties at runtime

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

ansible

免费

Create Ansible automation for configuring and updating servers. Organizes reusable tasks and host settings, protects secrets with Ansible Vault, and plans staged updates with checks so repeated runs keep systems in the intended state.

中文简介正在准备中。当前显示英语简介。

  • Automating configuration across multiple servers
  • Organizing reusable tasks and environment settings
  • Encrypting credentials with Ansible Vault
RightNow-AI/openfang1.8万2026年7月2日 更新

Test and debug REST and GraphQL APIs using curl, httpie, Postman collections, or scripted tests. Check authentication, invalid inputs, pagination, and response details to identify failures that a successful status code alone may miss.

中文简介正在准备中。当前显示英语简介。

  • Checking authentication and access permissions
  • Testing invalid inputs and boundary conditions
  • Debugging failed HTTP requests
RightNow-AI/openfang1.8万2026年7月2日 更新

aws

免费

Plan, deploy, and manage AWS infrastructure across computing, storage, networking, and serverless services. Get guidance on access permissions, backups, auditing, and cost management using AWS CLI and tools that define infrastructure in code.

中文简介正在准备中。当前显示英语简介。

  • Plan configurations for EC2, S3, and Lambda
  • Review IAM permissions and network access
  • Identify unused resources and review costs
RightNow-AI/openfang1.8万2026年7月2日 更新

azure

免费

Helps design and provision Microsoft Azure infrastructure using az CLI and Bicep configuration files. Covers choosing application hosting services, managing identities and secrets, designing networks, setting up monitoring, and organizing resources for cost management.

中文简介正在准备中。当前显示英语简介。

  • Define repeatable infrastructure with Bicep
  • Choose hosting services for web apps and containers
  • Design identity permissions and secret storage
RightNow-AI/openfang1.8万2026年7月2日 更新

Automate website searches, logins, form entry, and price comparisons using Playwright, a browser automation tool. Provides workflows for locating page elements, checking results, and recovering from navigation errors or missing elements.

中文简介正在准备中。当前显示英语简介。

  • Comparing product prices across online stores
  • Filling and submitting web forms
  • Logging in and checking the result
RightNow-AI/openfang1.8万2026年7月2日 更新

ci-cd

免费

Design automated build, test, and deployment workflows for GitHub Actions, GitLab CI/CD, and Jenkins. Covers job ordering, dependency caching, secret handling, and gradual releases that use health checks before expanding deployment.

中文简介正在准备中。当前显示英语简介。

  • Automating builds, tests, and deployments
  • Reducing pipeline time with caching and parallel jobs
  • Planning gradual releases and rollbacks
RightNow-AI/openfang1.8万2026年7月2日 更新

查看 RightNow-AI 的全部技能

报告此技能的问题