Skip to content
Back to skills

Type Generator

ASecurity

--- name: type-generator description: Generate TypeScript types and interfaces from JSON data, API responses, or database schemas ---

  • 33 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added February 10, 2026
developmenttypescriptbashapidatabasebackend

Works with

  • cli
  • api

Security analysis

A100/100

Scanned February 12, 2026

npx -y skills add lovedragonball/power-ranger-toolkit --skill type-generator --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Type Generator?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Type Generator
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/lovedragonball-type-generator/badge)](https://www.skillsdirectory.com/skills/lovedragonball-type-generator)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# 📝 Type Generator Skill

---
name: type-generator
description: Generate TypeScript types and interfaces from JSON data, API responses, or database schemas
---

## 🎯 Purpose

สร้าง TypeScript types และ interfaces อัตโนมัติจาก JSON data, API responses, หรือ database schemas

## 📋 When to Use

- ได้รับ JSON response จาก API
- ต้องการ types จาก database schema
- Convert JSON to TypeScript
- Sync types กับ backend

## 🔧 Generation Methods

### 1. From JSON Data

```json
// Input JSON
{
  "id": 1,
  "name": "John Doe",
  "email": "john@example.com",
  "isActive": true,
  "roles": ["admin", "user"],
  "profile": {
    "avatar": "https://...",
    "bio": "Developer"
  }
}
```

```typescript
// Generated TypeScript
interface User {
  id: number;
  name: string;
  email: string;
  isActive: boolean;
  roles: string[];
  profile: {
    avatar: string;
    bio: string;
  };
}
```

### 2. From API Response

```typescript
// Fetch and analyze
const response = await fetch('/api/users/1');
const data = await response.json();

// Generate type
type UserResponse = typeof data;
// or more precisely:
interface UserResponse {
  // ... inferred types
}
```

### 3. From Database Schema (Prisma)

```prisma
// schema.prisma
model User {
  id        Int      @id @default(autoincrement())
  email     String   @unique
  name      String?
  posts     Post[]
  createdAt DateTime @default(now())
}
```

```typescript
// Generated types (prisma generate)
interface User {
  id: number;
  email: string;
  name: string | null;
  posts: Post[];
  createdAt: Date;
}
```

## 📝 Type Generation Rules

### Primitive Inference
| JSON Value | TypeScript Type |
|------------|-----------------|
| `"string"` | `string` |
| `123` | `number` |
| `true/false` | `boolean` |
| `null` | `null` |
| `[]` | `T[]` (infer T) |
| `{}` | `interface/type` |

### Special Cases
| JSON Pattern | TypeScript |
|--------------|------------|
| `"2024-01-15"` | `string` (or `Date` with annotation) |
| `["a", 1]` | `(string \| number)[]` |
| Optional field | `field?: Type` |
| Mixed null | `Type \| null` |

## 🔧 Advanced Generation

### Union Types from Values
```typescript
// If JSON has limited values
{ "status": "active" } // or "inactive", "pending"

// Generate union
type Status = 'active' | 'inactive' | 'pending';
```

### Generic Types
```typescript
// API Response wrapper
interface ApiResponse<T> {
  data: T;
  success: boolean;
  message?: string;
}

// Usage
type UserResponse = ApiResponse<User>;
type UsersResponse = ApiResponse<User[]>;
```

### Partial and Required
```typescript
// From full type
interface User {
  id: number;
  name: string;
  email: string;
}

// Generate create DTO (without id)
type CreateUserDto = Omit<User, 'id'>;

// Generate update DTO (all optional)
type UpdateUserDto = Partial<CreateUserDto>;
```

## 📋 Generation Template

```typescript
// types/user.ts

// Base interface
export interface User {
  id: number;
  name: string;
  email: string;
  createdAt: string;
  updatedAt: string;
}

// Create DTO (for POST)
export type CreateUserDto = Omit<User, 'id' | 'createdAt' | 'updatedAt'>;

// Update DTO (for PATCH)
export type UpdateUserDto = Partial<CreateUserDto>;

// List response
export interface UserListResponse {
  data: User[];
  total: number;
  page: number;
  limit: number;
}

// Query params
export interface UserQueryParams {
  search?: string;
  page?: number;
  limit?: number;
  sortBy?: keyof User;
  order?: 'asc' | 'desc';
}
```

## 🛠️ Tools

### Online
- [quicktype.io](https://quicktype.io) - JSON to types
- [transform.tools](https://transform.tools) - Multiple formats

### CLI
```bash
# quicktype
npx quicktype sample.json -o types.ts

# json-schema-to-typescript
npx json-schema-to-typescript schema.json > types.ts
```

### VS Code
- JSON to TS extension
- Paste JSON as Code

## ✅ Type Quality Checklist

- [ ] All fields typed correctly
- [ ] Optional fields marked with `?`
- [ ] Nullable fields have `| null`
- [ ] Arrays properly typed
- [ ] Nested objects as interfaces
- [ ] Enums for fixed values
- [ ] DTOs for API calls
- [ ] Exported for use

## 🔗 Related Skills

- `api-client-generator` - Generate API clients
- `graphql-development` - GraphQL types
- `database-management` - Database schema types

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…