// TypeScript development best practices, code quality tools, and documentation templates. Activated when working with .ts, .tsx files or TypeScript projects.
| name | typescript-dev |
| description | TypeScript development best practices, code quality tools, and documentation templates. Activated when working with .ts, .tsx files or TypeScript projects. |
| allowed-tools | ["Read","Glob","Grep","Bash"] |
This skill supports TypeScript project development.
pnpm as package managernpm or yarnstrict: true required?. and nullish coalescing ??require()any type in production code# Format code
pnpm run format
# Run linter
pnpm run lint
# Type check
pnpm tsc --noEmit
# Run tests with coverage
pnpm test -- --coverage
/**
* Brief description of what the function does
*
* @description Detailed explanation of the business logic and purpose
* @param paramName - What this parameter represents
* @returns What the function returns and why
* @throws {ErrorType} When this error occurs
* @example
* ```typescript
* // Example usage
* const result = functionName({ key: 'value' });
* console.log(result); // Expected output
* ```
* @see {@link RelatedFunction} For related functionality
* @since 1.0.0
*/
export function functionName(paramName: ParamType): ReturnType {
// Implementation
}
/**
* Interface description
* @interface
*/
export interface UserProfile {
/** Unique user identifier */
id: string;
/** Username (3-20 characters) */
username: string;
/** Email address (verified) */
email: string;
/** Profile creation timestamp */
createdAt: Date;
}
/**
* Type representing user roles
* @typedef {('admin' | 'user' | 'guest')} UserRole
*/
export type UserRole = 'admin' | 'user' | 'guest';
Check these during code review:
any type usage?.) and Nullish coalescing (??) usedrequire())// Good: Clear error types
class ValidationError extends Error {
constructor(message: string, public field: string) {
super(message);
this.name = 'ValidationError';
}
}
// Good: Result type pattern
type Result<T, E = Error> =
| { success: true; data: T }
| { success: false; error: E };
// Good: With error handling
async function fetchUserData(id: string): Promise<Result<UserData>> {
try {
const response = await fetch(`/api/users/${id}`);
const data = await response.json();
return { success: true, data };
} catch (error) {
return { success: false, error: error as Error };
}
}
// Good: Custom type guard
function isUserProfile(value: unknown): value is UserProfile {
return (
typeof value === 'object' &&
value !== null &&
'id' in value &&
'username' in value
);
}
Avoid unnecessary re-renders (React)
React.memo for expensive componentsuseMemo / useCallback appropriatelyLazy Loading
React.lazy() for componentsType-only imports
import type { UserProfile } from './types';
โ Don't:
// Using any type
function process(data: any) { }
// Implicit any
function getValue(obj, key) { }
// Excessive type assertions
const user = data as User;
โ Do:
// Proper type definitions
function process(data: UserData) { }
// Explicit types
function getValue<T>(obj: T, key: keyof T) { }
// Use type guards
if (isUser(data)) {
// data is User here
}