"text":"A weekly newsletter focusing on development"
}
}
the following TS file would be generated:
// UsersEndpoint.d.ts
exportinterfaceUsersEndpoint{
page:number;
per_page:number;
total:number;
total_pages:number;
data:Datum[];
ad:Ad;
}
exportinterfaceAd{
company:string;
url:string;
text:string;
}
exportinterfaceDatum{
id:number;
email:string;
first_name:string;
last_name:string;
avatar:string;
}
interfaceRootextendsUsersEndpoint{}
Troubleshooting
You could pass boolean value isDiagnosticsFileCreated in the object as a second
argument to the validate function
import{validate}from"json-lint-d-ts";
constresult=validate([
["./hello.json","./hello.d.ts"],
],{
isDiagnosticsFileCreated:true,
});
This will generate a joined file near your json document hello.json.ts
with your types and json content where you could manually compare the difference.
How does all this work?
JSON validation:
Under the hood json-lint-d-ts uses Typescript Compiler by extending compiler host.
JSON objects are loaded from filesystem and compared against passed .d.ts files.
The result is extracted from diagnostics.
Typescript Schema generation:
For Typescript files generation from raw JSON quicktype is used