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.
npx skills add Gentleman-Programming/Gentleman-Skills --skill typescript -a claude-codeWhat 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
anyfrom 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-code2Manually: put the files in place
~/.claude/skills/typescript/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/typescript/
1Skills CLI (Vercel)
npx skills add Gentleman-Programming/Gentleman-Skills --skill typescript -a codex2Manually: put the files in place
.agents/skills/typescript/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add Gentleman-Programming/Gentleman-Skills --skill typescript -a cursor2Manually: put the files in place
.cursor/skills/typescript/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install Gentleman-Programming/Gentleman-Skills typescript2Manually: put the files in place
.github/skills/typescript/SKILL.md1Skills CLI (Vercel)
npx skills add Gentleman-Programming/Gentleman-Skills --skill typescript -a gemini-cli2Platform CLI
gemini skills install https://github.com/Gentleman-Programming/Gentleman-Skills --path curated/typescriptManually: put the files in place
.devin/skills/typescript/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add Gentleman-Programming/Gentleman-Skills --skill typescript -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
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.