typedescriptor
typedescriptor identifies and describes types.
Status
Category | Status |
---|
Version | |
Dependencies | |
Dev dependencies | |
Build | |
License | |
Installation
$ npm install typedescriptor
Quick Start
First you need to add a reference to typedescriptor to your application:
const Type = require('typedescriptor').default;
If you use TypeScript, use the following code instead:
import Type from 'typedescriptor';
Then, to identify a value's type, call the static of
function and hand over the value:
const type = Type.of('the native web');
console.log(type);
The types array
, boolean
, function
, null
, number
, object
, string
, symbol
and undefined
are supported.
Getting detailed type descriptions
To get a detailed type descriptor object, call the static from
function and hand over the value:
const typeDescriptor = Type.from('the native web');
console.log(typeDescriptor);
Using TypeScript type guards
Since using the descriptors above doesn't tell TypeScript anything, there are type guards for every type check:
import Type from 'typedescriptor';
const someValue = getSomeValue() as any;
if (Type.isArray(someValue)) {
}
if (Type.isValueType(someValue)) {
}
Running the build
To build this module use roboter.
$ npx roboter