TypeScript type information for compile-time validation of JSON objects.
npm install --save-dev json-typescript
import * as _JSON from 'json-typescript';
import * as { Value as JSONValue, Object as JSONObject } from 'json-typescript';
// ✅ This should be OK
let doc: JSONValue = {
data: {
type: 'articles',
id: '1'
}
};
// ⛔️ This should NOT be OK ( functions are not allowed )
let doc: JSONValue = {
foo() {
return bar;
}
};
// ⛔️ This should NOT be OK ( Array is not a JSONObject )
let doc: JSONObject = [];
© 2018 Mike North, All Rights Reserved.