This skill helps review and improve TypeScript code by applying best-practice patterns for types, interfaces, generics, and naming.
npx playbooks add skill vdustr/vp-claude-code-marketplace --skill typescript-best-practices
Guidelines for writing clean, type-safe, and maintainable TypeScript code.
> Note: If the repository has established code style conventions, follow those first. These guidelines serve as defaults.
interface for objects, type for unions/mapped/conditional<const TConfig> for strict literal inferencets-reset for saner built-in types| Use | When |
|-----|------|
| interface | Object structures, class contracts, extensible APIs |
| type | Union types, mapped types, conditional types, tuples |
| Element | Convention | Example |
|---------|------------|---------|
| Interface/Type | PascalCase | UserProfile, ResponseData |
| Generic parameters | T prefix | TUser, TConfig (never bare T, K, V) |
| Acronyms | First cap only | userId, ApiResponse (NOT userID, APIResponse) |
| Constants | UPPER_SNAKE | MAX_RETRY_COUNT |
| Variables/Functions | camelCase | getUserById, isActive |
| DO | DON'T |
|----|-------|
| Array<TItem> | TItem[] |
| ReadonlyArray<TItem> | readonly TItem[] |
| Use Case | DO | DON'T |
|----------|-----|-------|
| Empty object | Record<string, never> | {} |
| Any object (extends) | Record<string, any> | Record<string, unknown> |
| Any object (annotation) | Record<string, unknown> | Record<string, any> |
| Non-primitive | object | {} |
| DO | DON'T |
|----|-------|
| Zod/arktype for runtime validation | response as User |
| satisfies for compile-time checks | value as unknown as Type |
| Type guards (if ('prop' in obj)) | as any to silence errors |
| Explicit null checks | x! non-null assertion |
// DO: Type on the const
const myFunction: myFunction.Type = (options) => {
// implementation
};
// DO: satisfies when namespace doesn't exist
const onClick = ((event) => {
// implementation
}) satisfies React.ComponentProps<'button'>['onClick'];
// DO: Extract from existing definitions
type OnClick = React.ComponentProps<'button'>['onClick'];
type ItemIds = Array<Item['id']>;
type TimeoutType = NonNullable<typeof config['timeout']>;
// DON'T: Manually redefine types
type BadItemIds = Array<number>; // Won't update if Item.id changes
Before committing TypeScript code, verify:
interface for object types, type for unions/mapped/conditionalas or ! assertions — use Zod, satisfies, type guards, or explicit null checks.brand() or type-fest Tagged (not manual casting)T prefix for generics, Id not ID)For detailed patterns and examples, see:
*.test-d.ts filesWeekly roundup of top Claude Code skills, MCP servers, and AI coding tips.