Skip to content

schuchard/taap

Repository files navigation

Type Assertion And Predicate (Taap)

A lightweight zero dependency Typescript type checking library that coerces unknown value types. More concise and accurate than typeof checks or similar type checking methods.

github-workflows semantic-release styled with prettier

bundlephobia npm latest version npm next version

🛠 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

Supports optional generic return type:

Fixed return type:

Other:

About

A lightweight zero dependency Typescript type checking library that coerces unknown value types.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published