我是using这个TN-models-fp库来构建一个简单的API的基础上关闭的例子这里是我的api.ts
import { axios } from '../axios-instance'
import { createApi } from '@thinknimble/tn-models-fp'
import { todoShape } from './models'
const todoApi = createApi({
baseUri: '/api/todos',
client: axios,
models: {
entity: todoShape,
},
})
但我发现了一个错误
ype '{ entity: ZodObject<{ id: ZodNumber; title: ZodString; description: ZodString; completed: ZodBoolean; alertTime: ZodDate; createAlert: ZodBoolean; }, "strip", ZodTypeAny, { ...; }, { ...; }>; }' is not assignable to type '"You should not pass `create` model without an `entity` model"'.
这是我的zod形状
import { z } from 'zod'
export const todoShape = z.object({
id: z.number(),
title: z.string(),
description: z.string(),
completed: z.boolean(),
alertTime: z.date(),
createAlert: z.boolean(),
})
1条答案
按热度按时间rryofs0p1#
快速解决方法是从形状中删除
z.object
。形状应该是简单的对象,其值为zod类型。在文档中,我们有几个形状定义的例子。
错误绝对不是最好的,在这种情况下,所以好抓住!我们将在实体类型不是预期类型的情况下改进此错误
干杯!