leoyeai/openclaw-master-skills/typescript-coder
Claude Code and agent skill by leoyeai/openclaw-master-skills
- community
- ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
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-coderSemi-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.jsonfor a project - Working with
.ts,.tsx,.mts, or.d.tsfiles - 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
typescriptpackage (can be installed if needed)
Shorthand Keywords
Keywords to trigger this skill as if using a command-line tool:
Use these shorthand commands to quickly invoke TypeScript expertise without lengthy explanations. For example:
typescript-coder --check "this code"typescript-coder check this type guardts-coder migrate this filets-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:
Type Inference
TypeScript infers types when possible, reducing boilerplate:
Key TypeScript Features
| Feature | Purpose | When to Use | |
|---|---|---|---|
| Interfaces | Define object shapes | Defining data structures, API contracts | |
| Type Aliases | Create custom types | Union types, complex types, type utilities | |
| Generics | Type-safe reusable components | Functions/classes that work with multiple types | |
| Enums | Named constants | Fixed set of related values | |
| Type Guards | Runtime type checking | Narrowing union types safely | |
| Utility Types | Transform types | Partial<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:
- Install TypeScript as a dev dependency:
``bash npm install --save-dev typescript ``
- Install type definitions for Node.js (if using Node.js):
``bash npm install --save-dev @types/node ``
- Initialize TypeScript configuration:
``bash npx tsc --init ``
- 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"] } ``
- 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:
- Enable TypeScript to process JavaScript files:
``json { "compilerOptions": { "allowJs": true, "checkJs": false, "noEmit": true } } ``
- 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" }; ```
- Rename files incrementally from
.jsto.ts:
``bash # Start with utility files and leaf modules mv src/utils/helpers.js src/utils/helpers.ts ``
- Fix TypeScript errors in converted files:
- Add explicit type annotations where inference fails
- Define interfaces for complex objects
- Handle
anytypes appropriately - Add type guards for runtime checks
- Gradually convert remaining files:
- Start with utilities and shared modules
- Move to leaf components (no dependencies)
- Finally convert orchestration/entry files
- 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:
- 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; }; } ```
- 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; ```
- 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:
- 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 ```
- 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" }); ```
- 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:
- "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"; ```
- "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 ```
- `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; } ```
- 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
Browser/DOM Project
Library/Package
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
- SKILL.md in the repositoryCheckingskills/typescript-coder/SKILL.md
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
[](https://verified-skill.com/skills/leoyeai/openclaw-master-skills/typescript-coder)