0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

fix(schema): fix zod guard infer type for option fields (#148)

fix manual guard infer type breaks optional zod field type
This commit is contained in:
simeng-li 2021-12-02 17:22:39 +08:00 committed by GitHub
parent a56d4ce026
commit d54f77d78a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,8 +1,10 @@
import { ZodObject, ZodType } from 'zod';
import { ZodObject, ZodType, ZodOptional } from 'zod';
export type Guard<T extends Record<string, unknown>> = ZodObject<
{
[key in keyof T]: ZodType<T[key]>;
[key in keyof T]-?: undefined extends T[key]
? ZodOptional<ZodType<Exclude<T[key], undefined>>>
: ZodType<T[key]>;
}
>;