js-type-descriptor
v1.0.0
Published
Allows types to be described with JavaScript, and computes TypeScript types from those descriptions.
Downloads
4
Readme
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
Typetype2
Type
"union"
type1
Typetype2
Type
"instanceof"
value
constructor to use in the instanceof comparison
"object"
properties
A plain object with string keys and Type values