Agent skill

Typescript Best Practices

by jwynia in jwynia/agent-skills

Guide AI agents through TypeScript coding best practices including type safety, error handling, code organization, and architecture patterns.

MITAuto-check passedDevelopment

Install Typescript Best Practices

skills CLI
$ npx skills add jwynia/agent-skills --skill typescript-best-practices -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install jwynia/agent-skills typescript-best-practices --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/jwynia/agent-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/tech/development/tooling/typescript-best-practices .claude/skills/typescript-best-practices && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
typescript-best-practices
GitHub stars
169
Token cost
~2.5k tokens
SKILL.md length
359 words
Files
19 (incl. scripts, references, assets)
Skills in repo
111
Repo updated
First seen
Licence
MIT

At a glance

Guide AI agents through TypeScript coding best practices including type safety, error handling, code organization, and architecture patterns.

  • Works in 4 steps: Type Safety First → Immutability by Default → Error Handling with Types → …
  • Asks about TypeScript patterns
  • SKILL.md covers When to Use This Skill, Core Principles, Quick Reference and Code Generation Guidelines, plus 3 more sections
  • Calls deno

What it does

Typescript Best Practices is an agent skill from jwynia/agent-skills. Guide AI agents through TypeScript coding best practices including type safety, error handling, code organization, and architecture patterns. This skill should be used when generating TypeScript code, reviewing TypeScript files, creating new TypeScript modules, refactoring JavaScript to TypeScript, or when the user asks about TypeScript patterns, types, or coding standards. Keywords: typescript, types, coding standards, best practices, type safety, generics, architecture, refactoring.

Its SKILL.md is about 2.5k tokens, which your agent loads only when the skill is triggered. The skill folder holds 26 other files, including scripts, reference files and assets (for example `assets/templates/module-template.ts.md`, `assets/templates/service-template.ts.md` and `assets/tsconfig-presets/recommended.json`). Compatibility notes: Requires Deno for analysis scripts. Applicable to any TypeScript codebase.

It sits in Development, covering Type safety, Code quality and Software architecture. It works with TypeScript and JavaScript. The licence is MIT.

When your agent uses it

  • Asks about TypeScript patterns
  • Coding standards

Example prompts

  • “/typescript-best-practices”

Requirements

  • Node.js
  • Compatibility (from SKILL.md): Requires Deno for analysis scripts. Applicable to any TypeScript codebase.

Workflow steps

4 steps, taken from the step headings in SKILL.md.

  1. Type Safety First
  2. Immutability by Default
  3. Error Handling with Types
  4. Code Organization

What it can do on your machine

Read from SKILL.md and the folder at commit e02ec7e. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Ships 1 file in scripts/, which the agent can run.

    Shell commands in SKILL.md call:

    • deno

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

  • Compatibility

    Requires Deno for analysis scripts. Applicable to any TypeScript codebase.

    From compatibility in the SKILL.md frontmatter.

Context cost

Typescript Best Practices loads about 2.5k tokens when it runs, and up to ~26k if it reads all its reference files. Until then it costs about 129 tokens; SKILL.md has 359 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~129
When it runs · the whole SKILL.md, loaded when a task matches
~2.5k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~26k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); the scripts in this folder are not scanned.

SKILL.md

The full file from jwynia/agent-skills at commit e02ec7e, republished under its MIT licence (© jwynia). 359 words, ~2,490 tokens.

Download SKILL.mdSave it as .claude/skills/typescript-best-practices/SKILL.md (or your agent's skills folder). This skill also uses 18 other files; get the full folder from GitHub.
name
typescript-best-practices
description
Guide AI agents through TypeScript coding best practices including type safety, error handling, code organization, and architecture patterns. This skill should be used when generating TypeScript code, reviewing TypeScript files, creating new TypeScript modules, refactoring JavaScript to TypeScript, or when the user asks about TypeScript patterns, types, or coding standards. Keywords: typescript, types, coding standards, best practices, type safety, generics, architecture, refactoring.
compatibility
Requires Deno for analysis scripts. Applicable to any TypeScript codebase.
license
MIT
metadata.author
agent-skills
metadata.version
1.0
metadata.type
utility
metadata.mode
assistive
metadata.domain
development

TypeScript Best Practices

Guide AI agents in writing high-quality TypeScript code. This skill provides coding standards, architecture patterns, and tools for analysis and scaffolding.

When to Use This Skill

Use this skill when:

  • Generating new TypeScript code
  • Reviewing TypeScript files for quality issues
  • Creating new modules, services, or components
  • Refactoring JavaScript to TypeScript
  • Answering questions about TypeScript patterns or types
  • Designing APIs or interfaces

Do NOT use this skill when:

  • Working with pure JavaScript (no TypeScript)
  • Debugging runtime errors (use debugging tools)
  • Framework-specific patterns (React, Vue, etc. - use framework skills)

Core Principles

1. Type Safety First

Maximize compile-time error detection:

typescript
// Prefer unknown over any for unknown types
function processInput(data: unknown): string {
  if (typeof data === "string") return data;
  if (typeof data === "number") return String(data);
  throw new Error("Unsupported type");
}

// Explicit return types for public APIs
export function calculateTotal(items: ReadonlyArray<Item>): number {
  return items.reduce((sum, item) => sum + item.price, 0);
}

// Use const assertions for literal types
const CONFIG = {
  mode: "production",
  version: 1,
} as const;
2. Immutability by Default

Prevent accidental mutations:

typescript
// Use readonly for object properties
interface User {
  readonly id: string;
  readonly email: string;
  name: string; // Only mutable if intentional
}

// Use ReadonlyArray for collections
function processItems(items: ReadonlyArray<Item>): ReadonlyArray<Result> {
  return items.map(transform);
}

// Prefer spreading over mutation
function updateUser(user: User, name: string): User {
  return { ...user, name };
}
3. Error Handling with Types

Use the type system for error handling:

typescript
// Result type for recoverable errors
type Result<T, E = Error> =
  | { success: true; value: T }
  | { success: false; error: E };

// Typed error classes
class ValidationError extends Error {
  constructor(
    message: string,
    readonly field: string,
    readonly code: string
  ) {
    super(message);
    this.name = "ValidationError";
  }
}

// Function with Result return type
function parseConfig(input: string): Result<Config, ValidationError> {
  try {
    const data = JSON.parse(input);
    if (!isValidConfig(data)) {
      return {
        success: false,
        error: new ValidationError("Invalid config", "root", "INVALID_FORMAT"),
      };
    }
    return { success: true, value: data };
  } catch {
    return {
      success: false,
      error: new ValidationError("Parse failed", "root", "PARSE_ERROR"),
    };
  }
}
4. Code Organization

Structure code for maintainability:

typescript
// One concept per file
// user.ts - User type and related utilities
export interface User {
  readonly id: string;
  readonly email: string;
  readonly createdAt: Date;
}

export function createUser(email: string): User {
  return {
    id: crypto.randomUUID(),
    email,
    createdAt: new Date(),
  };
}

// Explicit exports (no barrel file wildcards)
// index.ts
export { User, createUser } from "./user.ts";
export { validateEmail } from "./validation.ts";

Quick Reference

CategoryPreferAvoid
Unknown typesunknownany
CollectionsReadonlyArray<T>T[] for inputs
ObjectsReadonly<T>Mutable by default
Null checksOptional chaining ?.!= null
Type narrowingType guardsas assertions
Return typesExplicit on exportsInferred on exports
EnumsString literal unionsNumeric enums
ImportsNamed importsDefault imports
ErrorsResult typesThrowing for flow control
Loopsfor...of, .map()for...in on arrays

Code Generation Guidelines

When generating TypeScript code, follow these patterns:

Module Structure
typescript
/**
 * Module description
 * @module module-name
 */

// === Types ===
export interface ModuleOptions {
  readonly setting: string;
}

export interface ModuleResult {
  readonly data: unknown;
}

// === Constants ===
const DEFAULT_OPTIONS: ModuleOptions = {
  setting: "default",
};

// === Implementation ===
export function processData(
  input: unknown,
  options: Partial<ModuleOptions> = {}
): ModuleResult {
  const opts = { ...DEFAULT_OPTIONS, ...options };
  // Implementation
  return { data: input };
}
Function Design
typescript
// Pure functions preferred
function transform(input: Input): Output {
  // No side effects, same input = same output
  return { ...input, processed: true };
}

// Explicit parameter types
function fetchUser(id: string, options?: FetchOptions): Promise<User> {
  // Implementation
}

// Use function overloads for complex signatures
function parse(input: string): ParsedData;
function parse(input: Buffer): ParsedData;
function parse(input: string | Buffer): ParsedData {
  // Implementation
}
Interface Design
typescript
// Prefer interfaces for object shapes
interface UserData {
  readonly id: string;
  readonly email: string;
}

// Use type for unions and intersections
type UserRole = "admin" | "user" | "guest";
type AdminUser = UserData & { readonly role: "admin" };

// Document with JSDoc
/**
 * Configuration for the API client
 * @property baseUrl - The base URL for API requests
 * @property timeout - Request timeout in milliseconds
 */
interface ApiConfig {
  readonly baseUrl: string;
  readonly timeout?: number;
}
Show full SKILL.md (155 more words)Show less

Common Anti-Patterns

Avoid these patterns when generating code:

Anti-PatternProblemSolution
any typeDisables type checkingUse unknown and narrow
as assertionsRuntime errorsUse type guards
Non-null !Null pointer errorsOptional chaining ?.
Mutable paramsUnexpected mutationsReadonly<T>
Magic stringsTypos, no autocompleteString literal types
God classesHard to test/maintainSingle responsibility
Circular depsBuild/runtime issuesDependency inversion
Index signaturesLose type infoExplicit properties

See references/anti-patterns/common-mistakes.md for detailed examples.

Scripts Reference

analyze.ts

Analyze TypeScript code for quality issues:

bash
deno run --allow-read scripts/analyze.ts <path> [options]

Options:
  --strict        Enable all checks
  --json          Output JSON for programmatic use
  --fix-hints     Show suggested fixes

Examples:
  # Analyze a file
  deno run --allow-read scripts/analyze.ts ./src/utils.ts

  # Analyze directory with strict mode
  deno run --allow-read scripts/analyze.ts ./src --strict

  # JSON output for CI
  deno run --allow-read scripts/analyze.ts ./src --json
generate-types.ts

Generate TypeScript types from JSON data:

bash
deno run --allow-read --allow-write scripts/generate-types.ts <input> [options]

Options:
  --name <name>   Root type name (default: inferred)
  --output <path> Output file path
  --readonly      Generate readonly types
  --interface     Use interface instead of type

Examples:
  # Generate from JSON file
  deno run --allow-read scripts/generate-types.ts ./data.json --name Config

  # Generate readonly interface
  deno run --allow-read --allow-write scripts/generate-types.ts ./api-response.json \
    --interface --readonly --output ./types/api.ts
scaffold-module.ts

Create properly structured TypeScript modules:

bash
deno run --allow-read --allow-write scripts/scaffold-module.ts [options]

Options:
  --name <name>   Module name (required)
  --path <path>   Target directory (default: ./src)
  --type <type>   Type: service, util, component
  --with-tests    Include test file

Examples:
  # Create a utility module
  deno run --allow-read --allow-write scripts/scaffold-module.ts \
    --name "string-utils" --type util

  # Create a service with tests
  deno run --allow-read --allow-write scripts/scaffold-module.ts \
    --name "user-service" --type service --with-tests

Additional Resources

Type System Deep Dives
  • references/type-system/advanced-types.md - Generics, conditional types, mapped types
  • references/type-system/type-guards.md - Type narrowing techniques
  • references/type-system/utility-types.md - Built-in utility types
Pattern Guides
  • references/patterns/error-handling.md - Result types, typed errors
  • references/patterns/async-patterns.md - Async/await best practices
  • references/patterns/functional-patterns.md - Immutability, composition
  • references/patterns/module-patterns.md - Exports, dependency injection
Architecture
  • references/architecture/project-structure.md - Directory organization
  • references/architecture/api-design.md - Interface design, versioning
Templates
  • assets/templates/module-template.ts.md - Module starter template
  • assets/templates/service-template.ts.md - Service class template
  • assets/tsconfig-presets/strict.json - Maximum strictness config
  • assets/tsconfig-presets/recommended.json - Balanced defaults

© jwynia, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 18 other files (scripts, references, assets) in skills/tech/development/tooling/typescript-best-practices of jwynia/agent-skills.

  • SKILL.md
  • assets/templates/module-template.ts.md
  • assets/templates/service-template.ts.md
  • assets/tsconfig-presets/recommended.json
  • assets/tsconfig-presets/strict.json
  • references/anti-patterns/common-mistakes.md
  • references/architecture/api-design.md
  • references/architecture/project-structure.md
  • references/patterns/async-patterns.md
  • references/patterns/error-handling.md
  • references/patterns/functional-patterns.md
  • references/patterns/module-patterns.md
  • references/type-system/advanced-types.md
  • … and 6 more

Open the folder on GitHubat commit e02ec7e

Compare with similar skills

Typescript Best Practices next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Typescript Best Practices compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Typescript Best Practices this skilljwynia/agent-skills169—~2.5kAutomated safety check: PassMIT
DRY Refactoring With jscpdkucherenko/jscpd6.4k—~2.1kAutomated safety check: PassMIT
jscpd Duplicate Code Detectorkucherenko/jscpd6.4k—~4.5kAutomated safety check: PassMIT
Fallow Setupfallow-rs/fallow-skills129—~1.1kAutomated safety check: PassMIT
Code ReviewerLeoYeAI/openclaw-master-skills2.2k1 repos~1.2kAutomated safety check: PassMIT
Typescript Writeaiskillstore/marketplace4302 repos~1.7kAutomated safety check: PassNone

Similar skills

  • Removes copy-paste duplication found by jscpd, starting with exact clones and hotspots, then renamed and near-miss copies, using proven refactoring strategies.

    6.4k GitHub stars~2.1k tokensUpdated today
    DevelopmentAuto-check passed
  • Finds duplicated code in 220+ languages with jscpd, reports exact, renamed and near-miss clones in a compact agent-friendly format and measures duplication.

    6.4k GitHub stars~4.5k tokensUpdated today
    DevelopmentAuto-check passed
  • Fallow Setup

    fallow-rs/fallow-skills

    Set up or modernize code-quality tooling for JavaScript and TypeScript projects.

    129 GitHub stars~1.1k tokensUpdated today
    DevelopmentAuto-check passed
  • Code Reviewer

    LeoYeAI/openclaw-master-skills

    Code review automation for TypeScript, JavaScript, Python, Go, Swift, Kotlin.

    2.2k GitHub starsUsed in 1 repo~1.2k tokens
    DevelopmentAuto-check passed
  • Typescript Write

    aiskillstore/marketplace

    Write TypeScript and JavaScript code following Metabase coding standards and best practices.

    430 GitHub starsUsed in 2 repos~1.7k tokens
    DevelopmentAuto-check passed
  • Code Reviewer

    borghei/Claude-Skills

    Code review automation for TypeScript, JavaScript, Python, Go, Swift, and Kotlin.

    886 GitHub stars~1.7k tokensUpdated 2 days ago
    DevelopmentAuto-check passed

More from jwynia/agent-skills

All 111 skills in this repo
  • Devcontainer

    jwynia/agent-skills

    Diagnose devcontainer configuration problems and guide development environment setup.

    169 GitHub stars~1.2k tokensUpdated 7 mo ago
    Auto-check: notes
  • Frontend Design

    jwynia/agent-skills

    Create distinctive, production-grade frontend interfaces with high design quality.

    169 GitHub stars~3.2k tokensUpdated 7 mo ago
    Auto-check passed
  • Gitea Workflow

    jwynia/agent-skills

    Orchestrate agile development workflows for Gitea repositories using the tea CLI.

    169 GitHub stars~3.8k tokensUpdated 7 mo ago
    Auto-check passed
  • Godot Asset Generator

    jwynia/agent-skills

    Generate game assets using AI image generation APIs (DALL-E, Replicate, fal.ai) and prepare them for Godot.

    169 GitHub stars~3.8k tokensUpdated 7 mo ago
    Auto-check passed
  • Mastra Hono

    jwynia/agent-skills

    Develop AI agents, tools, and workflows with Mastra v1 Beta and Hono servers.

    169 GitHub stars~2.9k tokensUpdated 7 mo ago
    Auto-check passed
  • PPTX Generator

    jwynia/agent-skills

    Create and manipulate PowerPoint PPTX files programmatically.

    169 GitHub stars~3.1k tokensUpdated 7 mo ago
    Auto-check passed

Categories

Questions about Typescript Best Practices

What does Typescript Best Practices do?

Guide AI agents through TypeScript coding best practices including type safety, error handling, code organization, and architecture patterns. Typescript Best Practices is an agent skill from jwynia/agent-skills. Guide AI agents through TypeScript coding best practices including type safety, error handling, code organization, and architecture patterns.

When should I use Typescript Best Practices?

Typescript Best Practices fits situations like: asks about TypeScript patterns; coding standards.

How do I install Typescript Best Practices in Claude Code?

Run `npx skills add jwynia/agent-skills --skill typescript-best-practices -a claude-code`. Or copy the skill folder (skills/tech/development/tooling/typescript-best-practices in jwynia/agent-skills) into .claude/skills/typescript-best-practices in your project. Claude Code loads it when a task matches its description.

How do I install Typescript Best Practices in Codex?

Run `npx skills add jwynia/agent-skills --skill typescript-best-practices -a codex`. Or copy the skill folder (skills/tech/development/tooling/typescript-best-practices in jwynia/agent-skills) into .agents/skills/typescript-best-practices in your project. Codex loads it when a task matches its description.

Can I use Typescript Best Practices in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add jwynia/agent-skills --skill typescript-best-practices -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/typescript-best-practices, .gemini/skills/typescript-best-practices, .github/skills/typescript-best-practices and .opencode/skills/typescript-best-practices in your project.

What does Typescript Best Practices need to run?

Going by SKILL.md and its folder, Typescript Best Practices needs the command-line tools its instructions call (deno). Our summary lists: Node.js. Compatibility (from SKILL.md): Requires Deno for analysis scripts. Applicable to any TypeScript codebase..

Does Typescript Best Practices access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Typescript Best Practices safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. The check reads SKILL.md only: the scripts in the folder are not scanned, so read them before running anything.

What licence does Typescript Best Practices use?

Typescript Best Practices is published under the MIT licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Typescript Best Practices use?

About 2.5k tokens (SKILL.md is roughly 10k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 23k tokens, read only when the agent opens those files.

What are the alternatives to Typescript Best Practices?

Skills that share tags, products or a category with Typescript Best Practices: DRY Refactoring With jscpd (kucherenko/jscpd, 6.4k stars), jscpd Duplicate Code Detector (kucherenko/jscpd, 6.4k stars), Fallow Setup (fallow-rs/fallow-skills, 129 stars) and Code Reviewer (LeoYeAI/openclaw-master-skills, 2.2k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Typescript Best Practices?

jwynia (a GitHub user) maintains it in jwynia/agent-skills, which has 169 GitHub stars. The repository holds 111 skills in this directory. The repository was last updated on February 24, 2026.

Source: jwynia/agent-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.