0.0.5 • Published 6 years ago

jsonapi.ts v0.0.5

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

JSON.ts

TypeScript ambient type information for compile-time validation of JSON:API documents.

How to use this

  1. Install this package
npm install --save-dev jsonapi.ts
  1. Include this module in your tsconfig.json's typeRoots
{
  "compilerOptions": {
    "typeRoots": [
      "node_modules/@types",
      "node_modules/json-typescript",
      "node_modules/jsonapi.ts"
    ]
  },
  "exclude": [
    "node_modules"
  ]
}
  1. check to see if json types are validated correctly
// ✅ This should be OK
let 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 = [];

Copyright

© 2017 Mike North, All Rights Reserved.