InvokeAI/invokeai/frontend/web/src/extend-zod.ts
psychedelicious e840de27ed feat(ui): extend zod with a is typeguard` method
Feels dangerous, but it's very handy.
2024-05-08 08:39:18 -04:00

9 lines
231 B
TypeScript

import { assert } from 'tsafe';
import { z } from 'zod';
assert(!Object.hasOwn(z.ZodType.prototype, 'is'));
z.ZodType.prototype.is = function (val: unknown): val is z.infer<typeof this> {
return this.safeParse(val).success;
};