taap
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

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.

📚 Docs   ⚡ Demo   💻 Repo

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

📚Full documentation

Supports optional generic return type:

Fixed return type:

Other:

Package Sidebar

Install

npm i taap

Weekly Downloads

1

Version

1.2.0

License

MIT

Unpacked Size

44.2 kB

Total Files

11

Last publish

Collaborators

  • schuchard