For the complete documentation index, see llms.txt. This page is also available as Markdown.

is

is is meant to be used in conjunction with assert and enable you to tell the compiler:

"Trust me this value is of type T" or "Trust me this value is not of type T"

import { assert, is } from "tsafe/assert";

type Circle = { radius: number };
type Square = { sideLength: number };
type Shape = Circle | Square;

declare const shape: Shape;

//You: Trust me TypeScript, I know that shape is a Circle.
assert(is<Circle>(shape));

//TypeScript: Ok if you say so...it has a radius then.
shape.radius;

Equally useful you can tell TypeScript that your shape is not a Square, it will infer that, it is then a Circle.

Last updated

Was this helpful?