Package Exports
- json-ts
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (json-ts) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
TS implementation of json2ts
Automatically generate Typescript Definition files based on JSON input. This allows a frontend to verify it's using a backend correctly & optionally tie it into a CI environment.
Example
Given the following JSON
(that could be on disk, or retrieved via a HTTP request)
{
"date": "01/02/03",
"summary": {
"url": "http://example.com",
"path": "/where",
"loc": {
"lat": 10,
"lng": 11
}
}
}
... this tool will produce the following Typescript definitions
interface IRootObject {
date: string;
summary: ISummary;
}
interface ISummary {
url: string;
path: string;
loc: ILoc;
}
interface ILoc {
lat: number;
lng: number;
}
TODO:
options
- Allow choice of
I
prefix on interface names - Allow naming of RootObject
- Allow choice of spaces/tabs
Core
- support array types
- support boolean types
- support null types
- PascalCase as default for all interface names
- de-dupe interfaces (it's dumb atm, POC)
- union types for array that contain mixed types:
nums: [1, "2"] -> nums: number|string[]
- handle none-valid names - where it's valid in JSON (cuz it's a string) - but not a valid identifier in output TS file
- Allow wrapping in namespace: eg:
declare namespace Projects { export interface ILoc { lat: number; lng: number; } ... }
CLI
- CLI tool to accept json file as input
- CLI tool to accept URL as input (for validating against remote API)
- configurable output (filename/stdout etc)