1.0.0 • Published 5 years ago
js-type-descriptor v1.0.0
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-descriptorconst {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"valuesArray of allowed values
"array"subtypeType of the items in the array
"literal"valueThe value of the literal
"intersection"type1Typetype2Type
"union"type1Typetype2Type
"instanceof"valueconstructor to use in the instanceof comparison
"object"propertiesA plain object with string keys and Type values
1.0.0
5 years ago