TypeScript type information for compile-time validation of JSON:API documents. Supports TS 2.3 and above.
How to use this
Install this package
npm install --save-dev jsonapi-typescript
Import this module
import * as JSONAPI from'jsonapi-typescript';
check to see if json types are validated correctly
import * as JSONAPI from'jsonapi-typescript';
// ✅ This should be OKlet doc: JSONAPI.Document = {
data: {
type: 'articles',
id: '1'
}
};
// ⛔️ This should NOT be OK ("result" is not a valid JSON:API top-level key)let doc: JSONAPI.Document = {
result: "Success!"
};
// ⛔️ This should NOT be OK ( empty Array is not a valid JSON:API document )let doc: JSONAPI.Document = [];
A JSON object MUST be at the root of every JSON API request and responsecontaining data.
This object defines a document’s “top level”.
A document MUST contain at least one of the following top-level members:
A JSON object MUST be at the root of every JSON API request and responsecontaining data. This object defines a document’s “top level”. A document MUST contain at least one of the following top-level members: