Skip to content
Back to skills

Typescript Best Practices

ASecurity

Use when writing or changing TypeScript or JavaScript files (.ts, .tsx, .js, tsconfig.json).

  • 2 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added October 16, 2026
ai-agentsjavascripttypescriptrustjavanodetestingapi

Works with

  • api

Security analysis

A100/100

Scanned December 1, 2026

npx -y skills add alleneubank/agent-profile --skill typescript-best-practices --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Typescript Best Practices?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Typescript Best Practices
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/alleneubank-typescript-best-practices/badge)](https://www.skillsdirectory.com/skills/alleneubank-typescript-best-practices)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: typescript-best-practices
description: Use when writing or changing TypeScript or JavaScript files (.ts, .tsx, .js, tsconfig.json).
---

# TypeScript Best Practices

Follows the type, error, and assertion law in `code-law`. This skill covers language-specific idioms only.

**Restrict who can do it** — when only one scope may perform an effect, keep its functions unexported and export only the scope that performs it; a branded capability that the scope alone creates makes an out-of-scope call a type error. Hold module boundaries with ESLint's shipped `no-restricted-imports` rule. Correct types are the proof.

## Runtime Validation with Zod

- Define schemas as single source of truth; infer TypeScript types with `z.infer<>`. Avoid duplicating types and schemas.
- Use `safeParse` for user input where failure is expected; use `parse` at trust boundaries where invalid data is a bug.
- Zod's method names changed between major versions. Read the installed version from `package.json` and its types under `node_modules` before relying on remembered APIs.

## Test Doubles

`toHaveBeenCalledWith` / `toHaveBeenNthCalledWith` on a `vi.fn()` standing in for your own module assert the call sequence, not the result — the change-detector shape in `testing-best-practices`. Mock at the network edge (`msw`) and assert the value the caller receives.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.