typescript-language-patterns
Modern TypeScript standards for type safety, performance, and maintainability.
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
TypeScript Language Patterns
Priority: P0 (CRITICAL)
Modern TypeScript standards for type-safe, maintainable code.
Implementation Guidelines
- Type Annotations: Explicit params/returns. Infer locals.
-
Interfaces vs Types:
interfacefor APIs.typefor unions. -
Strict Mode:
strict: true. -
Null Safety:
?.and??. -
Enums: Literal unions or
as const. - Generics: Reusable, type-safe code.
-
Type Guards:
typeof,instanceof, predicates. -
Utility Types:
Partial,Pick,Omit,Record. -
Immutability:
readonlyarrays/objects. -
Const Assertions:
as constandsatisfies. -
Template Literals:
on${Capitalize<string>}. -
Discriminated Unions: Literal
kindproperty. - Advanced: Mapped, Conditional, Indexed types.
-
Access: Default
public. Useprivate/protectedor#privatefor internals. -
Branded Types:
string & { __brand: 'Id' }.
Anti-Patterns
-
No
any: Useunknown. -
No
Function: Use signature() => void. -
No
enum: Runtime cost. -
No
!: Use narrowing.
Code
// Branded Type
type UserId = string & { __brand: 'Id' };
// Satisfies (Validate + Infer)
const cfg = { port: 3000 } satisfies Record<string, number>;
// Discriminated Union
type Result<T> = { kind: 'ok'; data: T } | { kind: 'err'; error: Error };
Reference & Examples
For advanced type patterns and utility types: See references/REFERENCE.md.
Related Topics
best-practices | security | tooling
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-01-20
- 索引更新时间
- 2026-01-26
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!