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