feat(ui): extend zod with a is typeguard` method

Feels dangerous, but it's very handy.
This commit is contained in:
psychedelicious 2024-05-07 16:45:07 +10:00 committed by Kent Keirsey
parent 8342f32f2e
commit e840de27ed
3 changed files with 18 additions and 0 deletions

View File

@ -0,0 +1,8 @@
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;
};

View File

@ -1,3 +1,5 @@
import 'extend-zod';
import ReactDOM from 'react-dom/client';
import InvokeAIUI from './app/components/InvokeAIUI';

View File

@ -0,0 +1,8 @@
import 'zod';
declare module 'zod' {
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
export interface ZodType<Output = any> {
is(val: unknown): val is Output;
}
}