Раньше, согласно https://stackoverflow.com/a/78156925/6727914,
zod records по умолчанию:
import { z } from 'zod'
const SomeEnum = z.enum(['one', 'two'])
const MyRecord = z.record(SomeEnum, z.boolean());
type MyRecordType = z.infer
// {
// one?: boolean | undefined;
// two?: boolean | undefined;
// }
const testA: MyRecordType = { one: true } // fine
Но это больше не так, как и https://github.com/colinhacks/zod/issue ... 2896874581
Так как я могу достичь эквивалента этого в Zod?{
baz: Partial;
}
< /code>
, чтобы я мог поймать пустой записью, как это: < /p>
const MyRecord = z.record(SomeEnum, z.boolean()).catch({});
< /code>
ошибка: < /p>
No overload matches this call.
Overload 1 of 2, '(def: Record): ZodCatch', gave the following error.
Argument of type '{}' is not assignable to parameter of type 'Record'.
Type '{}' is missing the following properties from type 'Record': one, two
Overload 2 of 2, '(def: (ctx: $ZodCatchCtx) => Record): ZodCatch', gave the following error.
Argument of type '{}' is not assignable to parameter of type '(ctx: $ZodCatchCtx) => Record'.
Type '{}' provides no match for the signature '(ctx: $ZodCatchCtx): Record'.ts(2769)
Подробнее здесь: https://stackoverflow.com/questions/797 ... ince-zod-4