360 Secure SkillHub
360 安全技能中心

Add Typescript Best Practices

该 Skill 按固定文本创建或更新项目中的 CLAUDE.md,写入 TypeScript 类型安全、接口优先、枚举、类型守卫、库优先、解构及时间配置等代码风格规则;可选参数用于指定要添加或避免的实践,不生成业务代码或安装依赖。

hahamumu08
hahamumu08
热度 39.59
最近更新 2026-05-11 17:43:59
分类:开发依赖:读写文件应用场景:模板

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add add-typescript-best-practices
Metadata
name
tech-stack:add-typescript-best-practices
description
Setup TypeScript best practices and code style rules in CLAUDE.md
argument-hint
Optional argument which practices to add or avoid

Setup TypeScript Best Practices

Create or update CLAUDE.md in with following content, write it strictly as it is, do not summaraise or introduce and new additional information:

## Code Style Rules

### General Principles

- **TypeScript**: All code must be strictly typed, leverage TypeScript's type safety features

### Code style rules

- Interfaces over types - use interfaces for object types
- Use enum for constant values, prefer them over string literals
- Export all types by default
- Use type guards instead of type assertions

### Best Practices

#### Library-First Approach

- Common areas where libraries should be preferred:
  - Date/time manipulation → date-fns, dayjs
  - Form validation → joi, yup, zod
  - HTTP requests → axios, got
  - State management → Redux, MobX, Zustand
  - Utility functions → lodash, ramda

#### Code Quality

- Use destructuring of objects where possible:
  - Instead of `const name = user.name` use `const { name } = user`
  - Instead of `const result = await getUser(userId)` use `const { data: user } = await getUser(userId)`
  - Instead of `const parseData = (data) => data.name` use `const parseData = ({ name }) => name`
- Use `ms` package for time related configuration and environment variables, instead of multiplying numbers by 1000