AGENT SKILL

typescript

Write clean, efficient TypeScript code that follows project conventions and advanced type patterns. Use when writing or reviewing TypeScript code, defining types, creating generics, handling errors, or working with React components, Zod schemas, and TanStack libraries.

License 许可
MIT
最近更新
2026-10-23
Stars
★ 1
Forks
0

01 前言 Front Matter

name
typescript
description
Write clean, efficient TypeScript code that follows project conventions and advanced type patterns. Use when writing or reviewing TypeScript code, defining types, creating generics, handling errors, or working with React components, Zod schemas, and TanStack libraries.
user-invocable
false

02 资源文件 1

03 SKILL.md 正文

TypeScript

Types are a correctness and clarity tool — reduce bugs, reduce cognitive load, no ceremony.

Compiler & Lint Constraints

  • strict: true — all strict checks enabled
  • verbatimModuleSyntax: true — always use import type for type-only imports
  • erasableSyntaxOnly: true — no enum, no parameter properties, no namespaces
  • consistent-type-imports: "error" — enforced by ESLint
  • noUnusedLocals / noUnusedParameters — prefix intentionally unused with _
  • Target/lib: ES2022, JSX: react-jsx. ES2022 = exact API ceiling for Vite baseline-widely-available (Vite 8: chrome111 / edge111 / firefox114 / safari16.4). No polyfills — no ES2023+ APIs (toSorted, toReversed, with, Object.groupBy, Promise.withResolvers, …). Same ceiling: ecmaVersion: 2022 (eslint.config.js). Bump all together, re-check every Vite major

Core Rules

  • PREFER type aliases for all type definitions
  • Use interface only for declaration merging (e.g., TanStack Register augmentation)
  • AVOID any — use unknown and narrow with type guards
  • AVOID enum — use union types or as const objects with ObjValues<typeof X> extraction
  • AVOID non-null assertions (!) unless no alternative exists
  • Let TypeScript infer when inference is clear and stable
  • Use explicit return types for exported/public functions
  • Use satisfies to validate values against types without widening

Constants Pattern

export const STATUS = { active: 'active', inactive: 'inactive' } as const;
export type Status = ObjValues<typeof STATUS>; // 'active' | 'inactive'

React Component Props

// Extend HTML elements
type ButtonProps = { isLoading?: boolean } & React.ComponentProps<'button'>;
// Narrow with Omit/Pick
type PasswordInputProps = Omit<InputProps, 'type'>;
// Compose with variants
type BadgeProps = React.ComponentProps<'span'> & VariantProps<typeof badgeVariants>;
  • Use React.ComponentProps<'element'> — not HTMLAttributes
  • Use React.PropsWithChildren when only children are needed
  • Never use React.FC with props — use function declarations with typed params

Zod Schema Inference

export type LoginSchema = z.infer<typeof loginSchema>;
export const loginSchema = z.object({ email: z.email(), password: z.string().min(8) });

Always export the inferred type above the schema for colocation.

Error Handling

  • Type errors explicitly with BaseErrorData<TData>
  • Use instanceof type guards for error narrowing (HTTPError, Error)
  • Handle form errors via formApi.setErrorMap with typed field error maps
  • Never swallow errors with broad catch — narrow and handle

Nullability

  • Handle null/undefined explicitly via control flow narrowing
  • Prefer ?? (nullish coalescing) over || for defaults
  • Use optional chaining (?.) — avoid deep nested null checks
  • Early-return pattern for optional parameters

Advanced Patterns

For generics, conditional types, mapped types, template literals, discriminated unions, type guards, and repo-specific patterns see [REFERENCE.md](mdc:REFERENCE.md).

04 同仓库更多 Skills

Phenomenon-Studio
Phenomenon-Studio/phenomenon-configs

web-security

Enforce web security and avoid security vulnerabilities.

★ 1
Phenomenon-Studio
Phenomenon-Studio/phenomenon-configs

typescript

Write clean, efficient TypeScript code that follows project conventions and advanced type patterns. Use when writing or reviewing TypeScript code, defining types, creating generics, handling errors, or working with React components, Zod schemas, and TanStack libraries.

★ 1
Phenomenon-Studio
Phenomenon-Studio/phenomenon-configs

tanstack-router

TanStack Router patterns for this repo — file-based routing, auth guards, search params, data loading, TanStack Query integration, navigation, and code splitting. Use when creating routes, adding pages, implementing auth flows, working with search/path params, or integrating loaders with TanStack Query.

★ 1
Phenomenon-Studio
Phenomenon-Studio/phenomenon-configs

tanstack-query

TanStack Query patterns for this repo — queryOptions/mutationOptions factories, query key hierarchies, service layer integration, optimistic updates, Suspense usage, error handling, and TanStack Router data loading. Use when creating queries, mutations, API services, query keys, cache invalidation, optimistic updates, or integrating data fetching with routes.

★ 1
Phenomenon-Studio
Phenomenon-Studio/phenomenon-configs

tanstack-form

Build forms using TanStack Form with the project's useAppForm composition, composable field components, Zod validation schemas, FormFieldWrapper error tracking, and form.AppField vs form.Field patterns. Use when creating new forms, adding form fields, writing form validation, or working with TanStack Form in this project.

★ 1
Phenomenon-Studio
Phenomenon-Studio/phenomenon-configs

react

Build clean, modern React components that apply common best practices and avoid common pitfalls like unnecessary state management or useEffect usage.

★ 1