mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): extend zod with a is
typeguard` method
Feels dangerous, but it's very handy.
This commit is contained in:
parent
8342f32f2e
commit
e840de27ed
8
invokeai/frontend/web/src/extend-zod.ts
Normal file
8
invokeai/frontend/web/src/extend-zod.ts
Normal 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;
|
||||
};
|
@ -1,3 +1,5 @@
|
||||
import 'extend-zod';
|
||||
|
||||
import ReactDOM from 'react-dom/client';
|
||||
|
||||
import InvokeAIUI from './app/components/InvokeAIUI';
|
||||
|
8
invokeai/frontend/web/src/zod-extensions.d.ts
vendored
Normal file
8
invokeai/frontend/web/src/zod-extensions.d.ts
vendored
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user