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

1.0.1 • Public • Published

safe-type-predicate

Build Status

Install

$ npm i safe-type-predicate

Usage

import { isT, isNotT, defineIsT } from "safe-type-predicate";
 
// isString: (x: unknown) => x is string
const isString = defineIsT((x: unknown) =>
    typeof x === "string" ? isT(x) : isNotT()
);
 
isString("x"); // true
isString(null); // false
 
// isA: (x: "a" | "b") => x is "a"
const isA = defineIsT((x: "a" | "b") =>
    x === "a" ? isT(x) : isNotT()
);
 
isA("a"); // true
isA("b"); // false
isA("c"); // Argument of type '"c"' is not assignable to parameter of type '"a" | "b"'

Readme

Keywords

none

Package Sidebar

Install

npm i safe-type-predicate

Weekly Downloads

10

Version

1.0.1

License

MIT

Unpacked Size

10.9 kB

Total Files

12

Last publish

Collaborators

  • kgtkr