# TypeScript best practices

> TypeScript best practices is an open-source agent skill for developer tools. Guides agents to write TypeScript with stronger types, safer boundaries and real tests. It is available on Claude Code.

- **Kind:** Skill
- **Pricing:** Open source
- **Platforms:** Claude Code
- **Website:** https://github.com/michael-denyer/pstack-claude/tree/main/plugins/pstack/skills/typescript-best-practices
- **Repository:** https://github.com/michael-denyer/pstack-claude
- **GitHub stars:** 5,057
- **License:** MIT
- **Skill name:** typescript-best-practices
- **Collection:** https://github.com/michael-denyer/pstack-claude
- **Categories:** [developer tools](https://ai-powered.com/categories/developer-tools)
- **Listing updated:** 2026-12-01

## About

This skill applies a set of TypeScript conventions whenever the agent reads or edits .ts or .tsx files. It steers modeling toward discriminated unions, branded types and constructive shapes that make illegal states unrepresentable, and it asks for narrowing through discriminants, type guards and satisfies instead of unchecked casts. External data is treated as unknown until parsed at the boundary, and the agent is pointed toward deriving types from runtime schemas rather than writing hand-rolled guards.

The skill also covers code hygiene and testing habits. It asks the agent to prefer structured logger diagnostics over console.log in shipped code, to use real test primitives instead of mocks where possible, and to verify UI in a running build. A companion examples file is included in the skill folder for worked patterns. It refers to other principle skills for type-system and boundary discipline, and it includes platform mapping notes for several non-Claude agents.

## When your agent uses it

> TypeScript best practices. Use when reading or editing any .ts or .tsx file.

## What it can access

From a static check of the files on GitHub; nothing was run.

- [Instructions only, no scripts](https://github.com/michael-denyer/pstack-claude/tree/HEAD/plugins/pstack/skills/typescript-best-practices)
- [License: MIT](https://github.com/michael-denyer/pstack-claude/tree/HEAD/plugins/pstack/skills/typescript-best-practices)

## Features

- **Discriminated union modeling:** Guides variant modeling with kind discriminants and avoids optional-field bags.
- **Safe type narrowing:** Sets a narrowing order and rules for type guards, with no casts before validation.
- **Boundary validation:** Parses external data as unknown into named domain types at entry points.
- **Exhaustiveness checks:** Adds never-typed default arms so new variants trigger compiler errors.
- **Schema-derived types:** Favors Pick, Omit, ReturnType and inference from runtime schemas over new interfaces.
- **Testing and telemetry habits:** Prefers real test primitives and structured logging over mocks and console.log.

## Good for

- Model a set of API response variants safely in TypeScript
- Replace unsafe as casts with validated parsing in a React component
- Add branded ID types so user and order IDs cannot be mixed up
- Refactor a function to use object arguments and a non-empty array type
- Review a .ts file for type-safety problems before merging

## Install

### Claude Code

This skill ships in the `pstack` plugin. In Claude Code, add the marketplace and install the plugin (it may include other skills too):

```sh
/plugin marketplace add michael-denyer/pstack-claude
/plugin install pstack@pstack-claude
```

Or copy only this skill to `~/.claude/skills/typescript-best-practices`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/michael-denyer/pstack-claude.git "$tmp" &&
mkdir -p ~/.claude/skills &&
rm -rf ~/.claude/skills/typescript-best-practices &&
cp -R "$tmp/plugins/pstack/skills/typescript-best-practices" ~/.claude/skills/typescript-best-practices &&
rm -rf "$tmp"
```

For one project only, put the folder in `.claude/skills/typescript-best-practices` inside it instead.

### Codex

Copy the skill folder to `~/.agents/skills/typescript-best-practices` to use it in every repository:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/michael-denyer/pstack-claude.git "$tmp" &&
mkdir -p ~/.agents/skills &&
rm -rf ~/.agents/skills/typescript-best-practices &&
cp -R "$tmp/plugins/pstack/skills/typescript-best-practices" ~/.agents/skills/typescript-best-practices &&
rm -rf "$tmp"
```

For one repository only, put the folder in `.agents/skills/typescript-best-practices` inside it instead.

### Cursor

Copy the skill folder to `~/.cursor/skills/typescript-best-practices` to use it in every project:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/michael-denyer/pstack-claude.git "$tmp" &&
mkdir -p ~/.cursor/skills &&
rm -rf ~/.cursor/skills/typescript-best-practices &&
cp -R "$tmp/plugins/pstack/skills/typescript-best-practices" ~/.cursor/skills/typescript-best-practices &&
rm -rf "$tmp"
```

For one project only, put the folder in `.cursor/skills/typescript-best-practices` inside it instead.

### Gemini CLI

Run in a terminal (add `--scope workspace` to install it for the current workspace only):

```sh
gemini skills install https://github.com/michael-denyer/pstack-claude.git --path plugins/pstack/skills/typescript-best-practices
```

Or copy the folder to `~/.gemini/skills/typescript-best-practices` yourself.

### VS Code

For GitHub Copilot in VS Code, copy the skill folder to `~/.copilot/skills/typescript-best-practices`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/michael-denyer/pstack-claude.git "$tmp" &&
mkdir -p ~/.copilot/skills &&
rm -rf ~/.copilot/skills/typescript-best-practices &&
cp -R "$tmp/plugins/pstack/skills/typescript-best-practices" ~/.copilot/skills/typescript-best-practices &&
rm -rf "$tmp"
```

For one project only, put the folder in `.github/skills/typescript-best-practices` inside it instead.

### Other agents

Get the folder:

```sh
git clone --depth 1 https://github.com/michael-denyer/pstack-claude.git
```

Then copy `pstack-claude/plugins/pstack/skills/typescript-best-practices` into your agent's skills folder as `typescript-best-practices`. Agents that support SKILL.md read one folder per skill.

## FAQ

### When does TypeScript best practices trigger?

It is loaded when the agent reads or edits any .ts or .tsx file, based on its paths setting.

### Does TypeScript best practices run any scripts?

No scripts are included. It consists of a SKILL.md instruction file and a reference examples file.

### Which agents does TypeScript best practices support?

The skill includes platform mapping references for Codex, GitHub Copilot, Muse and Antigravity, and it is packaged as a Claude Code plugin skill.

### How do I install TypeScript best practices in Claude Code?

Copy the skill folder from GitHub to ~/.claude/skills/typescript-best-practices to use it in all your projects, or to .claude/skills/typescript-best-practices in one project. Or install the pstack plugin, which includes it: /plugin marketplace add michael-denyer/pstack-claude, then /plugin install pstack@pstack-claude.

### Does TypeScript best practices run scripts?

No. It is instructions only, with no scripts. This comes from a static check of the files on GitHub; nothing was run. Read the files before you install it.

### Which AI agents can use TypeScript best practices?

Claude Code. It reads skills in the SKILL.md format; the install steps on this page show where to put the folder.

### What are the best alternatives to TypeScript best practices?

The closest alternatives to TypeScript best practices are Principle type system discipline, Readable code, JavaScript TypeScript jest, Coding standards and Principle model the domain.

## Where this comes from

- Description: from the skill's own SKILL.md.

## Alternatives

- [Principle type system discipline](https://ai-powered.com/skills/principle-type-system-discipline): Principle type system discipline is an open-source agent skill for developer tools.
- [Readable code](https://ai-powered.com/skills/readable-code): Readable code is an open-source agent skill for developer tools.
- [JavaScript TypeScript jest](https://ai-powered.com/skills/javascript-typescript-jest): JavaScript TypeScript jest is an open-source agent skill for developer tools.
- [Coding standards](https://ai-powered.com/skills/coding-standards-smartworldarafath): Coding standards is an open-source agent skill for developer tools.
- [Principle model the domain](https://ai-powered.com/skills/principle-model-the-domain): Principle model the domain is an open-source agent skill for developer tools.
- [Code simplifier](https://ai-powered.com/skills/code-simplifier): Code simplifier is an open-source agent skill for developer tools.
- [Antfu](https://ai-powered.com/skills/antfu): Antfu is an open-source agent skill for developer tools.
- [Patterns](https://ai-powered.com/skills/patterns-xiaolai): Patterns is an open-source agent skill for developer tools.

---
Source: https://ai-powered.com/skills/typescript-best-practices
