Agent-skills-standard typescript-best-practices
Write idiomatic TypeScript patterns for clean, maintainable code. Use when writing or refactoring TypeScript classes, functions, modules, or async logic. (triggers: **/*.ts, **/*.tsx, class, function, module, import, export, async, promise)
install
source · Clone the upstream repo
git clone https://github.com/HoangNguyen0403/agent-skills-standard
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/HoangNguyen0403/agent-skills-standard "$T" && mkdir -p ~/.claude/skills && cp -r "$T/.agent/skills/typescript/typescript-best-practices" ~/.claude/skills/hoangnguyen0403-agent-skills-standard-typescript-best-practices && rm -rf "$T"
manifest:
.agent/skills/typescript/typescript-best-practices/SKILL.mdsource content
TypeScript Best Practices
Priority: P1 (OPERATIONAL)
Implementation Guidelines
- Naming: Use
for Classes/Types/Interfaces,PascalCase
for variables/functions, andcamelCase
for static constants.UPPER_SNAKE - Functions: Use
for callbacks/logic;arrow functions
for top-level exports. Always typefunction declaration
returns.public API - Modules: Use
ONLY to enable better refactoring/auto-imports.Named exports - Async: Use
withasync/await
for parallel execution. ImplementPromise.all()
for error handling; typetry-catch
and narrow before use. Avoidcatch(e) as unknown
chains..then().catch() - Classes: Explicitly use
,private
, andprotected
modifiers. Favorpublic
over inheritance andcomposition
withdependency injection
and interfaces over singletons for testability.constructor injection - Type Safety: Use
for exhaustiveness checks in switch-cases.never - Optional: Use
(optional chaining
) and?.
(nullish coalescing
) over manual checks.?? - Imports: Enforce
order automatically viaexternal packages → internal modules → relative imports
. Useeslint-plugin-import
for interfaces/types to ensure better tree-shaking and zero runtime overhead.import type - Validation: Use
orZod
for runtime boundary validation.Tsoa
Anti-Patterns
- No Default Exports: Use named exports.
- No Implicit Returns: Specify return types.
- No Unused Variables: Enable
.noUnusedLocals - No
: Use ES6require
.import - No Empty Interfaces: Use
or non-empty interface.type - No
: Useany
or a specific type.unknown - No Unsafe Mocks: Cast with
orjest.Mocked<T>
.as unknown as T - No eslint-disable: Fix root cause; never suppress warnings.
References
See references/examples.md for Immutable Interfaces, Exhaustiveness Checking, Assertion Functions, DI Patterns, and Import Organization.