Typescript Best Practices
Write idiomatic TypeScript patterns for clean, maintainable code.
Install
npx skills add HoangNguyen0403/agent-skills-standard --skill typescript-best-practices -g -a claude-code -y- Repository
- HoangNguyen0403/agent-skills-standard582
- Category
- Writing
- Updated
- 3d ago
- License
- MIT
- Context cost
- Lightabout 564 tokens
- Runs scripts
- No, instructions only
What it does
Write idiomatic TypeScript patterns for clean, maintainable code. Use when writing or refactoring TypeScript classes, functions, modules, or async logic.
TypeScript Best Practices
Priority: P1 (HIGH)
Implementation Guidelines
- Naming: Use
PascalCasefor Classes/Types/Interfaces,camelCasefor variables/functions, andUPPER_SNAKEfor static constants. - Functions: Use
arrow functionsfor callbacks/logic;function declarationfor top-level exports. Always typepublic APIreturns. - Modules: Use
Named exportsONLY to enable better refactoring/auto-imports. - Async: Use
async/awaitwithPromise.all()for parallel execution. Implementtry-catchfor error handling; typecatch(e) as unknownand narrow before use. Avoid.then().catch()chains. - Classes: Explicitly use
private,protected, andpublicmodifiers. Favorcompositionover inheritance anddependency injectionwithconstructor injectionand interfaces over singletons for testability. - Type Safety: Use
neverfor exhaustiveness checks in switch-cases. - Optional: Use
optional chaining(?.) andnullish coalescing(??) over manual checks. - Imports: Enforce
external packages → internal modules → relative importsorder automatically viaeslint-plugin-import. Useimport typefor interfaces/types to ensure better tree-shaking and zero runtime overhead. - Validation: Use
ZodorTsoafor runtime boundary validation.
Anti-Patterns
- No Default Exports: Use named exports.
- No Implicit Returns: Specify return types.
- No Unused Variables: Enable
noUnusedLocals. - No
require: Use ES6import. - No Empty Interfaces: Use
typeor non-empty interface. - No
any: Useunknownor specific type. - No Unsafe Mocks: Cast with
jest.Mocked<T>oras unknown as T. - No eslint-disable: Fix root cause; never suppress warnings.
