@oada/types
TypeScript type definitions for OADA formats
Last updated 3 months ago by abalmos .
MIT · Repository · Original npm · Tarball · package.json
$ cnpm install @oada/types 
SYNC missed versions from official npm registry.

@OADA/types

This package is TypeScript type definitions for known OADA formats. These type are based on @OADA/formats.

Installation

yarn add @oada/types

Usage

The type definiton for a given format can be imported based on its $id. For example, the OADA Bookmarks v1 format can be imported like so:

/**
 * Import the type definition for
 * {@link https://formats.openag.io/oada/bookmarks/v1.schema.json}
 */
import Bookmarks from '@oada/types/oada/bookmarks/v1'

Runtime Validation

Since the formats are backed by schemas, it is possible to check data against a format at runtime. All the types in this package export methods for doing so which are typed properly for TypeScript to understand their type implications.

/**
 * Every type also exports both @method is and @method assert
 */
import Bookmarks, {is, assert} from '@oada/types/oada/bookmarks/v1'

const data1: any = /* Some data */

// True if data matches type Bookmarks, false if not
if (is(data1)) {
  // TS understands data is a bookmarks here
  const bookmarks: Bookmarks = data1
}

const data2: any = /* Some data */

// Throws if data is not of type Bookmarks
assert(data2)
// TS understands data is a bookmarks here
const bookmarks: Bookmarks = data2

Current Tags

  • 1.0.9-alpha.137                                ...           alpha (a month ago)
  • 1.0.10                                ...           latest (3 months ago)

12 Versions

  • 1.0.9-alpha.137                                ...           a month ago
  • 1.0.9-alpha.0                                ...           a month ago
  • 1.0.10                                ...           3 months ago
  • 1.0.9                                ...           3 months ago
  • 1.0.8                                ...           3 months ago
  • 1.0.7                                ...           3 months ago
  • 1.0.6                                ...           3 months ago
  • 1.0.5                                ...           3 months ago
  • 1.0.4                                ...           3 months ago
  • 1.0.3                                ...           3 months ago
  • 1.0.2                                ...           3 months ago
  • 1.0.1                                ...           3 months ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 15
Dependencies (3)
Dev Dependencies (14)

Copyright 2014 - 2017 © taobao.org |