Command Palette

Search for a command to run...

UnylyUnyly
Back to skills

typescript-coding-standards

FreeRuns bundled scriptsNot checked

TypeScript coding standards covering strict type system, advanced types, decorators, generics, and best practices for type-safe applications. Use for…

williamzujkowskiby williamzujkowski★ 23 GitHub stars13 installs in other catalogs

About this skill

TypeScript Coding Standards

Quick Navigation: Level 1: Quick Start (5 min) → Level 2: Implementation (30 min) → Level 3: Mastery (Extended)


Level 1: Quick Start (<2,000 tokens, 5 minutes)

Core Principles

  1. Strict Type Safety: Enable strict mode and leverage TypeScript's type system fully
  2. Type Inference: Use type inference when obvious, explicit types when clarity matters
  3. No Any: Avoid any type; use unknown for truly dynamic data
  4. Immutability: Prefer readonly properties and immutable data structures
  5. Modern Tooling: Use tsconfig strict mode, ESLint, and Prettier

Essential Checklist

  • Strict Mode: Enable all strict compiler options in tsconfig.json
  • No Implicit Any: All variables have explicit or inferred types
  • Proper Generics: Use generics for reusable type-safe functions and classes
  • Testing: Jest with TypeScript support, type testing with tsd
  • Documentation: TSDoc comments for public APIs
  • Module System: ES6 modules with proper imports/exports
  • Linting: ESLint with TypeScript plugin configured
  • Build: Proper tsconfig with source maps and declaration files

Quick Example

/**
 * Authentication service with type-safe error handling.
 */
import { hash, compare } from 'bcrypt';
import jwt from 'jsonwebtoken';

// Type definitions
interface User {
  readonly id: string;
  readonly username: string;
  readonly email: string;
  readonly passwordHash: string;
}

interface AuthResult<T> {
  readonly success: boolean;
  readonly data?: T;
  readonly error?: Error;
}

// Custom errors
class AuthError extends Error {
  constructor(message: string, public readonly code: string) {
    super(message);
    this.name = 'AuthError';
  }
}

// Service implementation
class AuthService {
  constructor(
    private readonly repository: UserRepository,
    private readonly jwtSecret: string
  ) {}

  async authenticate(username: string, password: string): Promise<AuthResult<{ token: string }>> {
    if (!username || !password) {
      return { success: false, error: new AuthError('Credentials required', 'VALIDATION') };
    }

    const user = await this.repository.findByUsername(username);
    if (!user || !await compare(password, user.passwordHash)) {
      return { success: false, error: new AuthError('Invalid credentials', 'AUTH_FAILED') };
    }

    const token = jwt.sign({ userId: user.id, username: user.username }, this.jwtSecret, {
      expiresIn: '1h',
    });

    return { success: true, data: { token } };
  }

  async hashPassword(password: string): Promise<string> {
    return hash(password, 10);
  }
}

Quick Links to Level 2


Level 2: Implementation (<5,000 tokens, 30 minutes)

Type System Fundamentals

Basic Types and Type Inference

// ✅ Good: Type inference when obvious
const username = 'alice'; // inferred as string
const count = 42; // inferred as number
const items = [1, 2, 3]; // inferred as number[]

// ✅ Good: Explicit types for clarity
function calculateTotal(items: number[]): number {
  return items.reduce((sum, item) => sum + item, 0);
}

// ❌ Bad: Unnecessary explicit types
const name: string = 'bob'; // Unnecessary, inference is clear

// ✅ Good: Union types for multiple possibilities
type Status = 'pending' | 'approved' | 'rejected';
let orderStatus: Status = 'pending';

// ✅ Good: Intersection types for composition
type Timestamped = { createdAt: Date; updatedAt: Date };
type User = { id: string; name: string };
type TimestampedUser = User & Timestamped;

// ✅ Good: Readonly for immutability
interface Config {
  readonly apiUrl: string;
  readonly timeout: number;
}

const config: Readonly<Config> = {
  apiUrl: 'https://api.example.com',
  timeout: 5000,
};

Type Guards and Narrowing

// Type guard functions
function isString(value: unknown): value is string {
  return typeof value === 'string';
}

function isUser(obj: unknown): obj is User {
  return (
    typeof obj === 'object' &&
    obj !== null &&
    'id' in obj &&
    'username' in obj
  );
}

// Using type guards
function processValue(value: string | number) {
  if (typeof value === 'string') {
    // value is string here
    return value.toUpperCase();
  }
  // value is number here
  return value.toFixed(2);
}

// Discriminated unions
type Success<T> = { success: true; data: T };
type Failure = { success: false; error: Error };
type Result<T> = Success<T> | Failure;

function handleResult<T>(result: Result<T>): T | null {
  if (resul
Full SKILL.md on GitHub

Install typescript-coding-standards in Claude Code & Claude Desktop

Sign up to install this skill

Create a free account to reveal the install command and save the skill to your library.

  • Reveal the one-line install command
  • Save skills to your synced library
  • Get notified when skills update
Sign up freeI already have an account

Allowed tools

Tools this skill is permitted to call.

No restriction — this skill can use any tool.

Bundled files

config/eslint.config.jsconfig/tsconfig.strict.jsonresources/README.mdresources/configs/.eslintrc.typescript.jsonresources/configs/tsconfig.base.jsonresources/configs/tsconfig.jsonscripts/README.mdtemplates/README.mdtemplates/branded-types.tstemplates/generic-component.tstemplates/generic-function.tstemplates/type-definitions.d.tstemplates/utility-types.ts

FAQ

What does the typescript-coding-standards skill do?

TypeScript coding standards covering strict type system, advanced types, decorators, generics, and best practices for type-safe applications. Use for TypeScript projects requiring robust type safety and maintainable code.

How do I install the typescript-coding-standards skill?

Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.

Does the typescript-coding-standards skill run scripts?

Yes, this skill bundles executable scripts. Review the source before installing.

Related skills

Compare typescript-coding-standards with