打字稿类型
- 作者仓库星标 0
- 作者仓库 skills-registry
- 领域
- 工程开发
- 作者声明的智能体
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 88 / 100 · 启发式扫描,不代表运行安全
- 运行环境证据
- 未执行;当前没有隔离运行测试证据
- 作者 / 版本 / 许可证
- @tomevault-io · 未声明许可证
- 上下文用量评级
- 低消耗
- 接入复杂程度
- 即装即用
- 是否需要外部接口密钥
- 不需要
- 兼容的系统
- 未声明(默认跨平台)
- 运行环境要求
- 未检出明确要求
- 检测到的文件与系统行为
-
- 只读
- 允许写入 / 修改
- 网络行为
- 仅限本地
- 安装命令数
- 无(仅作为资料)
需要注意: 未声明工具权限范围;实际权限由运行环境决定。
# Typescript Types
## Goal
Generate complete TypeScript type code and file updates, not concept-only guidance.
## Required Folder Convention
Always follow this structure:
```text
src/
types/
auth/
types.ts
users/
types.ts
posts/
types.ts
common/
types.ts
index.ts
```
Rules:
- One feature per folder under `src/types/<feature>`.
- One `types.ts` file per feature folder.
- Do not mix multiple features in one types file.
- Shared definitions go only in `src/types/common/types.ts`.
- Re-export all feature/common types from `src/types/index.ts`.
## Generation Workflow
When asked to add or create types for a feature:
1. Create or update `src/types/<feature>/types.ts`.
2. Organize definitions in section order:
- Enums
- Core interfaces
- DTO interfaces
- Response interfaces
- Utility types
3. Update `src/types/index.ts` exports.
4. If request touches shared contracts, update `src/types/common/types.ts`.
5. If request extends `req.user`, update `src/types/express.d.ts` (not feature file).
## Interface vs Type Rules
Use interface for object shapes by default:
- Entities
- DTO objects
- API response object shapes
- Class contracts
- Objects likely to be extended
Use type for:
- Unions
- Intersections
- Primitive aliases
- Tuples
- Conditional and mapped utility types
- Closed definitions that should not be declaration-merged
Do not replace object interfaces with type aliases when interface is sufficient.
## Enum Rules
Use string enum or const enum only:
- Feature-specific enums in feature `types.ts`.
- Shared enums in `src/types/common/types.ts`.
Prefer union type over enum only for tiny, local-only literal sets.
Never generate numeric enums.
## Naming Rules
- Interface names: PascalCase
- Type aliases: PascalCase
- Enum names: PascalCase
- Enum members: SCREAMING_SNAKE_CASE
- Folders: lowercase singular
- File names: lowercase, use `types.ts`
## Integration Rules
- Controllers consume DTO interfaces for request typing.
- Services return typed entities/response interfaces.
- Middlewares use enums for role/status checks.
- Prisma model contracts should map 1:1 with entity interfaces.
- Derive public response types from entities using `Omit`/`Pick` (for example strip `passwordHash`).
- Express request extension belongs in `src/types/express.d.ts` only.
Use standardized API success/error shapes in common types for cross-feature consistency.
## Required Outputs Per Task
If user asks for feature types, generate:
- `src/types/<feature>/types.ts` with complete definitions.
- `src/types/index.ts` export update.
If user asks for shared types, generate:
- `src/types/common/types.ts` updates.
- `src/types/index.ts` export update.
If user asks interface/type/enum design question:
- Provide decision with examples.
- If project files are present, also generate concrete type code in correct files.
## References To Load
Read these references when generating:
- `references/decision-guide.md`
- `references/feature-templates.md`
- `references/utility-types.md`
## Output Style For This Skill
When triggered:
- Prefer file creation/edits with complete imports/exports.
- Produce ready-to-use interfaces/types/enums with no placeholders.
- Keep exports clean and centralized via `src/types/index.ts`.
---
> Source: [CharvitZalavadiya/GitChat](https://github.com/CharvitZalavadiya/GitChat) — distributed by [TomeVault](https://tomevault.io).
<!-- tomevault:4.0:skill_md:2026-05-22 -->
章节与文件索引
按说明文件中的顺序排列。
目标
所需文件夹约定
生成工作流程
接口与类型规则
枚举规则
文件/命令 -> src/types/<feature> · types.ts · src/types/common/types.ts · src/types/index.ts · src/types/<feature>/types.ts · req.user · src/types/express.d.ts · Omit
内容校验值 -> 2595c30e5a42
当前原文的自动摘译,尚未人工审校。
目标
生成完整的 TypeScript 类型代码和文件更新,而不是仅限概念的指导。
所需文件夹约定
始终遵循以下结构: 规则:
src/types/<feature>下每个文件夹一个功能。每个功能文件夹一个types.ts文件。不要在一种类型的文件中混合多种功能。生成工作流程
当要求添加或创建功能类型时:创建或更新
src/types/<feature>/types.ts。按部分顺序组织定义:枚举核心接口接口与类型规则
默认情况下使用对象形状的接口: 实体 DTO 对象 API 响应对象形状 类契约
枚举规则
仅使用字符串枚举或常量枚举:功能
types.ts中的特定于功能的枚举。src/types/common/types.ts中的共享枚举。仅对于小型、仅限本地的文字集,更喜欢联合类型而不是枚举。永远不要生成数字枚举。