is

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;Last updated
Was this helpful?