assert
import { assert } from "tsafe/assert";
declare const x: number | string;
assert(typeof x === "string");
x.toLowerCase(); //<= Here TypeScript knows that x is a stringfunction assert(condition) {
if (!condition) {
throw new Error();
}
}Assertion on types
import { assert } from "tsafe/assert";
type A = "foo" | "bar";
type B = "foo" | "bar" | "baz";
//You will get red squiggly lines if A does not extend B
assert<A extends B ? true : false>;assert + is
isError thrown
Last updated
Was this helpful?