---
name: TypeScript Best Practices
slug: typescript-best-practices
category: Quality
description: TypeScript Best Practices enforces modern TypeScript patterns and best practices when writing new code, reviewing pull requests, or refactoring JavaScript to TypeScript. It ensures const usage, explicit return types, interface preference, and avoidance of any, var, and @ts-ignore.
github: "https://github.com/rohitg00/skillkit/tree/main/packages/core/src/eval/__tests__/fixtures/good-skill"
language: TypeScript
stars: 1461
forks: 137
install: "npx degit https://github.com/rohitg00/skillkit/tree/main/packages/core/src/eval/__tests__/fixtures/good-skill ~/.claude/skills/good-skill"
installs_to: ~/.claude/skills/good-skill
source_path: packages/core/src/eval/__tests__/fixtures/good-skill/SKILL.md
collection_size: 17
category_size: 1354
collection_url: "https://dirskills.com/collections/rohitg00/skillkit"
added: 2026-08-19T07:27:16.085Z
last_synced: 2026-08-19T07:27:16.085Z
canonical_url: "https://dirskills.com/skills/typescript-best-practices"
---

# TypeScript Best Practices

TypeScript Best Practices enforces modern TypeScript patterns and best practices when writing new code, reviewing pull requests, or refactoring JavaScript to TypeScript. It ensures const usage, explicit return types, interface preference, and avoidance of any, var, and @ts-ignore.

**Install:**

```bash
npx degit https://github.com/rohitg00/skillkit/tree/main/packages/core/src/eval/__tests__/fixtures/good-skill ~/.claude/skills/good-skill
```

## README

# TypeScript Best Practices

## When to Use

Use this skill when:
- Writing new TypeScript code
- Reviewing TypeScript pull requests
- Refactoring JavaScript to TypeScript

## Triggers

Activated when editing `.ts` or `.tsx` files in the project.

## Rules

### Always
- Always use `const` for variables that won't be reassigned
- Always use explicit return types on exported functions
- Always prefer `interface` over `type` for object shapes

### Never
- Never use `any` — use `unknown` instead
- Never use `var` — use `const` or `let`
- Never ignore TypeScript errors with `@ts-ignore`

## Examples

```typescript
// Good: explicit return type
export function calculateTotal(items: Item[]): number {
  return items.reduce((sum, item) => sum + item.price, 0);
}
```

```typescript
// Good: discriminated union
type Result<T> =
  | { success: true; data: T }
  | { success: false; error: Error };
```

## Boundaries

- Do not modify `tsconfig.json` without explicit permission
- Do not add new dependencies without checking existing utilities
- Focus only on TypeScript patterns, not runtime behavior
