taap
v1.2.0
Published
A zero dependency Typescript type checking library that coerces unknown values.
Downloads
36
Maintainers
Readme
Type Assertion And Predicate (Taap
)
A lightweight zero dependency Typescript type checking library that coerces unknown values. More concise and accurate than typeof
checks or similar type checking methods.
🛠 Getting Started
Install dependency
npm i taap
Import and use methods
import { isArray } from 'taap';
const maybeArray: unknown = [];
if (typeof maybeArray === 'array') {
🚫 typeof [] === 'object'
} else if (isArray(maybeArray)) {
// `maybeArray` is now of type: `any[]`
✅ maybeArray.push(1);
}
Optionally supply a return type
import { isArray } from 'taap';
const maybeArray: unknown = [1, 2, 3];
if (isArray<number>(maybeArray)) {
// `maybeArray` is now of type: `number[]`
maybeArray.filter((x) => x > 1);
}
🔭 Available Methods
📚Full documentation
Supports optional generic return type:
Fixed return type:
Other: