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
- 参考文档REFERENCE.md6.7 KB
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 enabledverbatimModuleSyntax: true— always useimport typefor type-only importserasableSyntaxOnly: true— noenum, no parameter properties, no namespacesconsistent-type-imports: "error"— enforced by ESLintnoUnusedLocals/noUnusedParameters— prefix intentionally unused with_- Target/lib: ES2022, JSX:
react-jsx. ES2022 = exact API ceiling for Vitebaseline-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
typealiases for all type definitions - Use
interfaceonly for declaration merging (e.g., TanStackRegisteraugmentation) - AVOID
any— useunknownand narrow with type guards - AVOID
enum— use union types oras constobjects withObjValues<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
satisfiesto 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'>— notHTMLAttributes - Use
React.PropsWithChildrenwhen only children are needed - Never use
React.FCwith 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
instanceoftype guards for error narrowing (HTTPError,Error) - Handle form errors via
formApi.setErrorMapwith typed field error maps - Never swallow errors with broad
catch— narrow and handle
Nullability
- Handle
null/undefinedexplicitly 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
web-security
Enforce web security and avoid security vulnerabilities.
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.
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.
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.
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.
react
Build clean, modern React components that apply common best practices and avoid common pitfalls like unnecessary state management or useEffect usage.