
typescript
✓ Official★ 6,186by genkit-ai · part of genkit-ai/genkit
TypeScript coding conventions, best practices, and patterns for writing clean, maintainable code.
🧰 Not standalone. This skill ships with genkit-ai/genkit and only works together with that tool — install the tool first, then add this skill.
This is the playbook your agent receives when the skill activates — you don't need to read it to use the skill, but it's here to audit before installing.
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 middlewareError 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.
Copy & paste — that's it
npx skills add https://github.com/genkit-ai/genkit --skill typescriptRun this in your project — your agent picks the skill up automatically.
No common issues documented yet. If you hit a problem, the repository's GitHub Issues page is the best place to look.
Licensed under Apache-2.0— you can use, modify, and redistribute it under that license's terms.
View the full license file on GitHub →