JSON 转 Schema 博客 打开工具 →

JSON 怎么快速转 TypeScript 类型?

接一个返回 JSON 的接口,最烦的就是手写 interface。把 JSON 粘进工具,点「生成 TS 类型」就能拿到现成的类型定义。

更新于 2026-08-30 · 阅读约 3 分钟

一个例子

{
  "id": 1024,
  "name": "Ada Lovelace",
  "active": true,
  "tags": ["math", "computing"],
  "profile": { "city": "London", "followers": 1200 }
}

点「生成 TS 类型」得到:

export interface Root {
  id: number;
  name: string;
  active: boolean;
  tags: string[];
  profile: {
    city: string;
    followers: number;
  };
}

类型推导规则

常见坑

👉 打开工具,粘入你真实的接口返回值生成类型