Skip to content
/ taap Public

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

License

Notifications You must be signed in to change notification settings

schuchard/taap

Folders and files

NameName
Last commit message
Last commit date
Jul 7, 2020
Jul 7, 2020
Jul 10, 2020
Jul 3, 2020
Jul 3, 2020
Jul 10, 2020
Jul 4, 2020
Jul 3, 2020
Jul 10, 2020
Jul 3, 2020
Jan 28, 2021
Jul 10, 2020
Jul 3, 2020
Jul 3, 2020
Jul 3, 2020

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: