2.5k
GitHub Stars
2
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill openclaw/skills --skill type-gen- _meta.json482 B
- SKILL.md2.0 KB
Overview
This skill generates TypeScript interfaces from JSON data or API responses so you can stop writing types by hand. I provide a fast CLI that converts files, URLs, or piped JSON into ready-to-use interfaces or type aliases. It handles nested objects, arrays, unions, and common edge cases like empty arrays.
How this skill works
I parse the input JSON and infer TypeScript shapes for objects, arrays, primitives, and mixed arrays. Nested objects are extracted into separate interfaces and references are created for reuse. You can stream JSON from curl, point at a URL, or read local files, then output to stdout or write directly to a file.
When to use it
- Typing API responses during development or when integrating new endpoints
- Generating types for large JSON fixtures or sample responses
- Quickly scaffolding types for frontend apps consuming REST APIs
- Converting backend sample data into shared TypeScript definitions
- Automating type updates as mock data or API schemas change
Best practices
- Give a meaningful root name with -n to keep generated types readable
- Use -o to write outputs into a central src/types file for source control
- Prefer interfaces for extendable shapes and --type when you need union/alias patterns
- Review and adjust optional flags; --optional can be useful for loose responses
- Commit generated types as part of API contract updates, not transient debugging
Example use cases
- Curl a JSON API and convert to types: curl https://api.example.com/users | npx json-to-ts -n User
- Generate project typeset: npx json-to-ts responses.json -o src/types/api.ts -n ApiResponse
- Fetch live endpoint and inspect inferred shapes before implementation
- Convert mixed arrays into union types for safer runtime checks
- Handle unknown or empty arrays as unknown[] to force explicit handling
FAQ
Yes. Use -t or --type to output TypeScript type aliases instead of interfaces.
How does it handle empty arrays and mixed arrays?
Empty arrays are typed as unknown[] and mixed arrays become union types to represent all observed element shapes.