typescript-conventions
14
总安装量
6
周安装量
#24014
全站排名
安装命令
npx skills add https://github.com/jgamaraalv/ts-dev-kit --skill typescript-conventions
Agent 安装分布
opencode
6
claude-code
6
github-copilot
6
codex
6
kimi-cli
6
gemini-cli
6
Skill 文档
TypeScript Conventions
Project-wide TypeScript standards that complement agent-specific instructions.
Type Safety
- No
any: Useunknownif the type is truly dynamic, then narrow. - Strict config:
strict: true,noUncheckedIndexedAccess,verbatimModuleSyntax. - Use
Readonly<T>,Pick,Omit, andRecordfor precise types. - Use branded types for entity IDs (e.g.,
UserId,OrderId) to prevent mixing. - Prefer
z.infer<typeof schema>over hand-written types when a Zod schema exists.
Imports
// Type-only imports (required by verbatimModuleSyntax)
import type { FastifyInstance } from "fastify";
// Mixed imports: separate values and types
import { z } from "zod/v4";
import type { ZodType } from "zod/v4";
// ioredis: always named import
import { Redis } from "ioredis";
Error Handling
- Handle errors at the beginning of functions with early returns / guard clauses.
- Avoid deep nesting — use if-return pattern instead of else chains.
- In Fastify routes, throw
httpErrorsor usereply.status().send()— the centralizedsetErrorHandlerformats the response. - Custom error classes for domain-specific errors (e.g.,
NotFoundError,ConflictError).
Naming
- Functions:
getUserById,createReport,isActive,hasPermission - Booleans:
is/has/can/shouldprefix - Query (returns data):
get,find,list,fetch - Command (changes state):
create,update,delete,add,remove
Anti-Patterns
- Primitive obsession: Use branded types or Zod enums, not raw strings for IDs and statuses.
- Magic numbers/strings: Use constants from a shared package (e.g.,
RATE_LIMITS,PAGINATION,CACHE). - Long parameter lists: Use an options object or a Zod schema.
- Premature abstraction: Three similar lines > one premature helper. Abstract on the third repetition.