typescript-coder
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.
What this skill does
# 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
| 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:
1. **Install TypeScript as a dev dependency**:
```bash
npm install --save-dev typescript
```
2. **Install type definitions for Node.js** (if using Node.js):
```bash
npm install --save-dev @types/node
```
3. **Initialize TypeScript configuration**:
```bash
npx tsc --init
```
4. **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"]
}
```
5. **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
}
}
```
2. **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"
};
```
3. **Rename files incrementally** from `.js` to `.ts`:
```bash
# Start with utility files and leaf modules
mv src/utils/helpers.js src/utils/helpers.ts
```
4. **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
5. **Gradually convert remaining files**:
- Start with utilities and shared modules
- Move to leaf components (no dependencies)
- Finally convert orchestration/entry files
6. **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;
};
}
```
2. **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;
```
3. **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); Related in Code Review
gstack
IncludedFast headless browser for QA testing and site dogfooding. Navigate pages, interact with elements, verify state, diff before/after, take annotated screenshots, test responsive layouts, forms, uploads, dialogs, and capture bug evidence. Use when asked to open or test a site, verify a deployment, dogfood a user flow, or file a bug with screenshots. (gstack)
startup-due-diligence
IncludedLegal due diligence review for seed-stage and Series A startups (US, Delaware C-Corp focus). Supports both investor and founder perspectives. Capabilities include: (1) Interactive document review and issue spotting; (2) Document request list generation; (3) Cap table and SAFE/convertible note analysis; (4) Red flag identification with severity ratings; (5) Diligence report generation. TRIGGERS: due diligence, DD, startup investment, cap table review, Series A, seed round, investor diligence, legal review startup, SAFE analysis, convertible note, 409A, founder vesting.
interview-master
IncludedThis skill should be used when the user asks to "generate interview questions", "prepare for interview", "optimize resume", "conduct mock interview", "analyze git commits for resume", "generate resume from code", "review my resume", or mentions interview preparation, career assistance, or extracting project experience from git history. Provides comprehensive interview and career development guidance for both job seekers and interviewers.
fix-issue
IncludedFixes GitHub issues using parallel analysis agents for root cause investigation, code exploration, and regression detection. Reads issue context from gh CLI, searches codebase and memory for related patterns, generates a fix with tests, and links the resolution back to the issue via PR. Includes prevention analysis to avoid recurrence. Use when debugging errors, resolving regressions, fixing bugs, or triaging issues.
sf-apex
IncludedGenerates and reviews Salesforce Apex code with 150-point scoring. TRIGGER when: user writes, reviews, or fixes Apex classes, triggers, test classes, batch/queueable/schedulable jobs, or touches .cls/.trigger files. DO NOT TRIGGER when: LWC JavaScript (use sf-lwc), Flow XML (use sf-flow), SOQL-only queries (use sf-soql), or non-Salesforce code.
swift-development
IncludedComprehensive Swift development for building, testing, and deploying iOS/macOS applications. Use when Claude needs to: (1) Build Swift packages or Xcode projects from command line, (2) Run tests with XCTest or Swift Testing framework, (3) Manage iOS simulators with simctl, (4) Handle code signing, provisioning profiles, and app distribution, (5) Format or lint Swift code with SwiftFormat/SwiftLint, (6) Work with Swift Package Manager (SPM), (7) Implement Swift 6 concurrency patterns (async/await, actors, Sendable), (8) Create SwiftUI views with MVVM architecture, (9) Set up Core Data or SwiftData persistence, or any other Swift/iOS/macOS development tasks.