leoyeai/openclaw-master-skills/typescript-coder

Claude Code and agent skill by leoyeai/openclaw-master-skills

Trust tier 3
  • community
  • ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Source check pending

Checking that the SKILL.md file is still in the repository.

Expert 10x engineer with extensive knowledge of TypeScript fundamentals, migration strategies, and best practices. Use when asked to "add TypeScript", "migrate to TypeScript", "add type checking", "create TypeScript config", "fix TypeScript errors", or work with .ts/.tsx files. Supports JavaScript to TypeScript migration, JSDoc type annotations, tsconfig.json configuration, and type-safe code patterns.

Install

npx vskill@latest install leoyeai/openclaw-master-skills/typescript-coder

Semi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard

SKILL.md

The same SKILL.md was published earlier as leoyeai/openclaw-master-skills/typescript-coder.

TypeScript Coder Skill

Master TypeScript development with expert-level knowledge of type systems, migration strategies, and modern JavaScript/TypeScript patterns. This skill transforms you into a 10x engineer capable of writing type-safe, maintainable code and migrating existing JavaScript projects to TypeScript with confidence.

When to Use This Skill

  • User asks to "add TypeScript", "migrate to TypeScript", or "convert to TypeScript"
  • Need to "add type checking" or "fix TypeScript errors" in a project
  • Creating or configuring tsconfig.json for a project
  • Working with .ts, .tsx, .mts, or .d.ts files
  • Adding JSDoc type annotations to JavaScript files
  • Debugging type errors or improving type safety
  • Setting up TypeScript in a Node.js or JavaScript project
  • Creating type definitions or ambient declarations
  • Implementing advanced TypeScript patterns (generics, conditional types, mapped types)

Prerequisites

  • Basic understanding of JavaScript (ES6+)
  • Node.js and npm/yarn installed (for TypeScript compilation)
  • Familiarity with the project structure and build tools
  • Access to the typescript package (can be installed if needed)

Shorthand Keywords

Keywords to trigger this skill as if using a command-line tool:

javascript
openPrompt = ["typescript-coder", "ts-coder"]

Use these shorthand commands to quickly invoke TypeScript expertise without lengthy explanations. For example:

  • typescript-coder --check "this code"
  • typescript-coder check this type guard
  • ts-coder migrate this file
  • ts-coder --migrate project-to-typescript

Role and Expertise

As a TypeScript expert, you operate with:

  • Deep Type System Knowledge: Understanding of TypeScript's structural type system, generics, and advanced types
  • Migration Expertise: Proven strategies for incremental JavaScript to TypeScript migration
  • Best Practices: Knowledge of TypeScript patterns, conventions, and anti-patterns
  • Tooling Mastery: Configuration of TypeScript compiler, build tools, and IDE integration
  • Problem Solving: Ability to resolve complex type errors and design type-safe architectures

Core TypeScript Concepts

The TypeScript Type System

TypeScript uses structural typing (duck typing) rather than nominal typing:

typescript
interface Point {
x: number;
y: number;
}
// This works because the object has the right structure
const point: Point = { x: 10, y: 20 };
// This also works - structural compatibility
const point3D = { x: 1, y: 2, z: 3 };
const point2D: Point = point3D; // OK - has x and y
Type Inference

TypeScript infers types when possible, reducing boilerplate:

typescript
// Type inferred as string
const message = "Hello, TypeScript!";
// Type inferred as number
const count = 42;
// Type inferred as string[]
const names = ["Alice", "Bob", "Charlie"];
// Return type inferred as number
function add(a: number, b: number) {
return a + b; // Returns number
}
Key TypeScript Features
FeaturePurposeWhen to Use
InterfacesDefine object shapesDefining data structures, API contracts
Type AliasesCreate custom typesUnion types, complex types, type utilities
GenericsType-safe reusable componentsFunctions/classes that work with multiple types
EnumsNamed constantsFixed set of related values
Type GuardsRuntime type checkingNarrowing union types safely
Utility TypesTransform typesPartial<T>, Pick<T, K>, Omit<T, K>, etc.

Step-by-Step Workflows

Task 1: Install and Configure TypeScript

For a new or existing JavaScript project:

  1. Install TypeScript as a dev dependency:

``bash npm install --save-dev typescript ``

  1. Install type definitions for Node.js (if using Node.js):

``bash npm install --save-dev @types/node ``

  1. Initialize TypeScript configuration:

``bash npx tsc --init ``

  1. Configure `tsconfig.json` for your project:

``json { "compilerOptions": { "target": "ES2020", "module": "commonjs", "lib": ["ES2020"], "outDir": "./dist", "rootDir": "./src", "strict": true, "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "resolveJsonModule": true, "declaration": true, "declarationMap": true, "sourceMap": true }, "include": ["src/**/*"], "exclude": ["node_modules", "dist"] } ``

  1. Add build script to `package.json`:

``json { "scripts": { "build": "tsc", "dev": "tsc --watch", "check": "tsc --noEmit" } } ``

Task 2: Migrate JavaScript to TypeScript (Incremental Approach)

Safe, incremental migration strategy:

  1. Enable TypeScript to process JavaScript files:

``json { "compilerOptions": { "allowJs": true, "checkJs": false, "noEmit": true } } ``

  1. Add JSDoc type annotations to JavaScript files (optional intermediate step):

```javascript // @ts-check

/**

  • Calculates the sum of two numbers
  • @param {number} a - First number
  • @param {number} b - Second number
  • @returns {number} The sum

*/ function add(a, b) { return a + b; }

/** @type {string[]} */ const names = ["Alice", "Bob"];

/** @typedef {{ id: number, name: string, email?: string }} User */

/** @type {User} */ const user = { id: 1, name: "Alice" }; ```

  1. Rename files incrementally from .js to .ts:

``bash # Start with utility files and leaf modules mv src/utils/helpers.js src/utils/helpers.ts ``

  1. Fix TypeScript errors in converted files:
  • Add explicit type annotations where inference fails
  • Define interfaces for complex objects
  • Handle any types appropriately
  • Add type guards for runtime checks
  1. Gradually convert remaining files:
  • Start with utilities and shared modules
  • Move to leaf components (no dependencies)
  • Finally convert orchestration/entry files
  1. Enable strict mode progressively:

``json { "compilerOptions": { "strict": false, "noImplicitAny": true, "strictNullChecks": true // Enable other strict flags one at a time } } ``

Task 3: Define Types and Interfaces

Creating robust type definitions:

  1. Define interfaces for data structures:

```typescript // User data model interface User { id: number; name: string; email: string; age?: number; // Optional property readonly createdAt: Date; // Read-only property }

// API response structure interface ApiResponse<T> { success: boolean; data?: T; error?: { code: string; message: string; }; } ```

  1. Use type aliases for complex types:

```typescript // Union type type Status = 'pending' | 'active' | 'completed' | 'failed';

// Intersection type type Employee = User & { employeeId: string; department: string; salary: number; };

// Function type type TransformFn<T, U> = (input: T) => U;

// Conditional type type NonNullable<T> = T extends null | undefined ? never : T; ```

  1. Create type definitions in `.d.ts` files for external modules:

```typescript // types/custom-module.d.ts declare module 'custom-module' { export interface Config { apiKey: string; timeout?: number; }

export function initialize(config: Config): Promise<void>; export function fetchData<T>(endpoint: string): Promise<T>; } ```

Task 4: Work with Generics

Type-safe reusable components:

  1. Generic functions:

```typescript // Basic generic function function identity<T>(value: T): T { return value; }

const num = identity(42); // Type: number const str = identity("hello"); // Type: string

// Generic with constraints function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] { return obj[key]; }

const user = { name: "Alice", age: 30 }; const name = getProperty(user, "name"); // Type: string const age = getProperty(user, "age"); // Type: number ```

  1. Generic classes:

```typescript class DataStore<T> { private items: T[] = [];

add(item: T): void { this.items.push(item); }

get(index: number): T | undefined { return this.items[index]; }

filter(predicate: (item: T) => boolean): T[] { return this.items.filter(predicate); } }

const numberStore = new DataStore<number>(); numberStore.add(42);

const userStore = new DataStore<User>(); userStore.add({ id: 1, name: "Alice", email: "alice@example.com" }); ```

  1. Generic interfaces:

```typescript interface Repository<T> { findById(id: string): Promise<T | null>; findAll(): Promise<T[]>; create(item: Omit<T, 'id'>): Promise<T>; update(id: string, item: Partial<T>): Promise<T>; delete(id: string): Promise<boolean>; }

class UserRepository implements Repository<User> { async findById(id: string): Promise<User | null> { // Implementation return null; } // ... other methods } ```

Task 5: Handle Type Errors

Common type errors and solutions:

  1. "Property does not exist" errors:

```typescript // ❌ Error: Property 'name' does not exist on type '{}' const user = {}; user.name = "Alice";

// ✅ Solution 1: Define interface interface User { name: string; } const user: User = { name: "Alice" };

// ✅ Solution 2: Type assertion (use cautiously) const user = {} as User; user.name = "Alice";

// ✅ Solution 3: Index signature interface DynamicObject { [key: string]: any; } const user: DynamicObject = {}; user.name = "Alice"; ```

  1. "Cannot find name" errors:

```typescript // ❌ Error: Cannot find name 'process' const env = process.env.NODE_ENV;

// ✅ Solution: Install type definitions // npm install --save-dev @types/node const env = process.env.NODE_ENV; // Now works ```

  1. `any` type issues:

```typescript // ❌ Implicit any (with noImplicitAny: true) function process(data) { return data.value; }

// ✅ Solution: Add explicit types function process(data: { value: number }): number { return data.value; }

// ✅ Or use generic function process<T>(data: T): T { return data; } ```

  1. Union type narrowing:

```typescript function processValue(value: string | number) { // ❌ Error: Property 'toUpperCase' does not exist on type 'string | number' return value.toUpperCase();

// ✅ Solution: Type guard if (typeof value === "string") { return value.toUpperCase(); // TypeScript knows it's string here } return value.toString(); } ```

Task 6: Configure for Specific Environments

Environment-specific configurations:

Node.js Project
json
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"lib": ["ES2020"],
"types": ["node"],
"moduleResolution": "node",
"esModuleInterop": true
}
}
Browser/DOM Project
json
{
"compilerOptions": {
"target": "ES2020",
"module": "esnext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"moduleResolution": "bundler",
"resolveJsonModule": true,
"noEmit": true
}
}
Library/Package
json
{
"compilerOptions": {
"target": "ES2020",
"module": "esnext",
"declaration": true,
"declarationMap": true,
"outDir": "./dist",
"rootDir": "./src"
}
}

TypeScript Best Practices

Do's

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
2,157
Repository forks
324
7-day trend score
43

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Extension points

  • hookPre/post lifecycle hooks

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/leoyeai/openclaw-master-skills/typescript-coder/badge)](https://verified-skill.com/skills/leoyeai/openclaw-master-skills/typescript-coder)

Something wrong with this skill or its page? Tell us.