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

1.0.0 • Public • Published

safe-is-type-ts

Build Status

Install

$ npm i safe-is-type-ts

Usage

import { isType, isNotType, toIsTypeFunction } from "safe-is-type-ts";

// isString: (x: unknown) => x is string
const isString = toIsTypeFunction((x: unknown) =>
    typeof x === "string" ? isType(x) : isNotType()
);

isString("x"); // true
isString(null); // false

// isA: (x: "a" | "b") => x is "a"
const isA = toIsTypeFunction((x: "a" | "b") =>
    x === "a" ? isType(x) : isNotType()
);

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-is-type-ts

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

10.9 kB

Total Files

12

Last publish

Collaborators

  • kgtkr