AGENT SKILL
typescript
TypeScript coding conventions, best practices, and patterns for writing clean, maintainable code.
- License 许可
- Apache-2.0
- 所属仓库
- genkit-ai/genkit
- 最近更新
- 2026-11-11
- Stars
- ★ 6.6k
- Forks
- 879
01 前言 Front Matter
- name
- typescript
- description
- TypeScript coding conventions, best practices, and patterns for writing clean, maintainable code.
03 SKILL.md 正文
TypeScript Coding Conventions
General Principles
- Use TypeScript strict mode (
"strict": truein tsconfig.json). - Prefer
constoverlet; never usevar. - Use explicit return types on exported functions.
- Prefer interfaces over type aliases for object shapes.
- Use
unknowninstead ofanywhere possible.
Naming Conventions
- Variables & functions:
camelCase - Classes & interfaces:
PascalCase - Constants:
UPPER_SNAKE_CASEfor true constants,camelCasefor derived values - Files:
kebab-case.ts - Type parameters: Single uppercase letter (
T,K,V) or descriptive (TResult)
File Structure
src/
index.ts # Entry point, exports
types.ts # Shared type definitions
utils/ # Utility functions
services/ # Business logic
middleware/ # Express/framework middleware
Error Handling
- Use typed errors (extend
Errorclass). - Always handle promise rejections.
- Prefer
try/catchwith specific error types over generic catches.
class AppError extends Error {
constructor(
message: string,
public readonly code: string,
public readonly statusCode: number = 500
) {
super(message);
this.name = 'AppError';
}
}
Async Patterns
- Use
async/awaitover raw promises. - Use
Promise.all()for concurrent independent operations. - Avoid mixing callbacks and promises.
Imports
- Use named imports:
import { thing } from './module' - Group imports: external packages first, then internal modules.
- Use
.jsextensions in import paths for ESM compatibility.
Code Style
- Maximum line length: 100 characters.
- Use template literals for string interpolation.
- Prefer
Array.map/filter/reduceoverforloops for transformations. - Use optional chaining (
?.) and nullish coalescing (??). - Destructure objects and arrays when accessing multiple properties.
Testing
- Co-locate test files:
thing.ts→thing.test.ts - Use descriptive test names:
it('should return empty array when no items match') - Test edge cases: empty inputs, null values, error conditions.
04 同仓库更多 Skills
developing-genkit-tooling
Best practices for authoring Genkit tooling, including CLI commands and MCP server tools. Covers naming conventions, architectural patterns, and consistency guidelines.
★ 6.6k
test-writer
How to write pytest tests for modules in this workspace. Load whenever you are about to write or extend tests.
★ 6.6k
python-expert
Conventions for clean, idiomatic Python. Load whenever you read, edit, or write Python source files.
★ 6.6k
coding
A skill for coding that should apply to all coding tasks.
★ 6.6k
shakespeare
Respond in the style of William Shakespeare — early modern English, poetic cadence.
★ 6.6k
pirate
Respond in the voice of a swashbuckling pirate.
★ 6.6k