Skip to main content
skill CX Codex

typescript · gentleman-programming — Claude Code skill: strict TypeScript patterns

A skill that hands your agent a fixed set of strict TypeScript rules: const objects instead of union types, flat interfaces, no any. Useful when AI writes the code and you want one style.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add Gentleman-Programming/Gentleman-Skills --skill typescript -a claude-code
Open on GitHub

What typescript does

The skill spells out patterns the agent has to follow. Instead of a plain union type it builds a const object with as const and derives the type via (typeof STATUS)[keyof typeof STATUS]. Interfaces stay flat: a nested object becomes its own interface and gets referenced, never inlined.

any is off the table. Truly unknown values go through unknown and a type guard shaped like value is User; flexible signatures use generics. There is a reference list of utility types too: Pick, Omit, Partial, Required, Readonly, Record, Extract, Exclude, NonNullable, ReturnType, Parameters. Type imports use import type.

Install runs through npx skills add for Claude, Codex, Cursor, Gemini CLI and OpenCode; GitHub Copilot has its own gh skill install command. The skill file lands in the platform folder, for example ~/.claude/skills/typescript/SKILL.md. If your project already settled on a different typing style, these rules will fight it — worth checking who owns the standard before you add another one.

What it helps with

  • swap union types for const objects with derived types
  • move nested objects out into separate interfaces
  • strip any from agent-written code
  • pick the right utility type instead of hand-rolling one
  • add a type guard for unknown input

Example prompts for the agent

  • write the Status type using the const object pattern
  • rewrite this interface without inline nested objects
  • replace any with unknown and add a type guard

How to install typescript

1Skills CLI (Vercel)

npx skills add Gentleman-Programming/Gentleman-Skills --skill typescript -a claude-code

2Manually: put the files in place

~/.claude/skills/typescript/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/typescript/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about typescript

How do I install typescript in Claude?

Run npx skills add Gentleman-Programming/Gentleman-Skills --skill typescript -a claude-code. The file ends up at ~/.claude/skills/typescript/SKILL.md.

What does the typescript skill do?

It gives the agent strict TypeScript rules: const objects instead of union types, flat interfaces, unknown and generics instead of any, and type imports via import type.

Which platforms does the skill support?

Claude, Codex, Cursor, GitHub Copilot, Gemini CLI and OpenCode. Each platform has its own install command and its own skills folder.

Source text

SKILL.md · Apache-2.0
---
name: typescript
description: >
  TypeScript strict patterns and best practices.
  Trigger: When writing TypeScript code - types, interfaces, generics.
license: Apache-2.0
metadata:
  author: gentleman-programming
  version: "1.0"
---

## Const Types Pattern (REQUIRED)

```typescript
// ✅ ALWAYS: Create const object first, then extract type
const STATUS = {
  ACTIVE: "active",
  INACTIVE: "inactive",
  PENDING: "pending",
} as const;

type Status = (typeof STATUS)[keyof typeof STATUS];

// ❌ NEVER: Direct union types
type Status = "active" | "inactive" | "pending";
```

**Why?** Single source of truth, runtime values, autocomplete, easier refactoring.

## Flat Interfaces (REQUIRED)

```typescript
// ✅ ALWAYS: One level depth, nested objects → dedicated interface
interface UserAddress {
  street: string;
  city: string;
}

interface User {
  id: string;
  name: string;
  address: UserAddress;  // Reference, not inline
}

interface Admin extends User {
  permissions: string[];
}

// ❌ NEVER: Inline nested objects
interface User {
  address: { street: string; city: string };  // NO!
}
```

## Never Use `any`

```typescript
// ✅ Use unknown for truly unknown types
function parse(input: unknown): User {
  if (isUser(input)) return input;
  throw new Error("Invalid input");
}

// ✅ Use generics for flexible types
function first<T>(arr: T[]): T | undefined {
  return arr[0];
}

// ❌ NEVER
function parse(input: any): any { }
```

## Utility Types

```typescript
Pick<User, "id" | "name">     // Select fields
Omit<User, "id">              // Exclude fields
Partial<User>                 // All optional
Required<User>                // All required
Readonly<User>                // All readonly
Record<string, User>          // Object type
Extract<Union, "a" | "b">     // Extract from union
Exclude<Union, "a">           // Exclude from union
NonNullable<T | null>         // Remove null/undefined
ReturnType<typeof fn>         // Function return type
Parameters<typeof fn>         // Function params tuple
```

## Type Guards

```typescript
function isUser(value: unknown): value is User {
  return (
    typeof value === "object" &&
    value !== null &&
    "id" in value &&
    "name" in value
  );
}
```

## Import Types

```typescript
import type { User } from "./types";
import { createUser, type Config } from "./utils";
```

## Keywords
typescript, ts, types, interfaces, generics, strict mode, utility types

© gentleman-programming · Apache-2.0 · Gentleman-Programming/Gentleman-Skills

Similar skills

All skills for Programming languages →

typescript by other authors comes first.

typescript PyModel A skill with 44 rules on types, tsconfig and async code. Useful when your agent edits compiler config or untangles heavy generics. CX Codex +1 520installs typescript alinaqi Tells the agent how to write and check TypeScript: strict tsconfig, ESLint config, Jest tests and a layered project layout. Kicks in on .ts and .tsx files. CX Codex +1 313installs typescript Mindrally Enforces strict TypeScript standards and functional code patterns in your AI assistant. It bans any, replaces enums with maps, and caps function length at 20 lines. CX Codex +1 955installs typescript-magician mcollina Resolves TypeScript compiler errors, eliminates any types, and creates strict generic patterns. Useful when locking down codebase type safety. CX Codex +1 2,800installs typescript-advanced-types sickn33 Teaches the agent generics, conditional and mapped types in TypeScript, and stays honest about where type checking stops. CX Codex +1 1,300installs typescript-discriminated-unions mkosir Guides coding agents to apply discriminated unions in TypeScript, eliminating invalid states and enabling exhaustiveness checks. CX Codex +1 3,800installs typescript-pro https://github.com/Jeffallan Implements advanced TypeScript type systems, branded types, and tRPC configurations. Use it when building type-first APIs or complex discriminated unions. CX Codex +1 14,200installs go-interfaces cxuu Guides coding agents through Go interface design, type composition, and compile-time checks. Prevents premature abstractions in public APIs. CX Codex +1 1,200installs langgraph-typescript-quickstart langchain-ai Scaffolds a minimal local LangGraph agent in TypeScript following official docs. Useful when testing graph architectures locally without polluting existing repositories. CX Codex +1 5,000installs

From the same set4

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor