js-type-descriptor
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.0 • Public • Published

    Type Descriptor

    Allows types to be described with JavaScript, and computes TypeScript types from those descriptions. Can be used to validate the structure of an object, or anything else where type information is required in the runtime.

    Usage

    npm i js-type-descriptor
    const {isType} = require('js-type-descriptor');
    
    if (isType(value, {kind: 'string'} as const)) {
      // value is a string
    }

    Types

    • "string"
    • "number"
    • "boolean"
    • "null"
    • "undefined"
    • "symbol"
    • "bigint"
    • "any"
    • "enum"
      • values Array of allowed values
    • "array"
      • subtype Type of the items in the array
    • "literal"
      • value The value of the literal
    • "intersection"
      • type1 Type
      • type2 Type
    • "union"
      • type1 Type
      • type2 Type
    • "instanceof"
      • value constructor to use in the instanceof comparison
    • "object"
      • properties A plain object with string keys and Type values

    Keywords

    none

    Install

    npm i js-type-descriptor

    DownloadsWeekly Downloads

    6

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    7.16 kB

    Total Files

    5

    Last publish

    Collaborators

    • joeleinbinder