-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(type->api): resultField推断api的返回值应该包含recordbale类型 #3699
feat(type->api): resultField推断api的返回值应该包含recordbale类型 #3699
Conversation
f5a0287
to
c93d803
Compare
能说下这么做的原因吗? |
举一个例子,例如我有如下代码 <template>
<PageWrapper title="上传组件示例">
<BasicForm @register="register" class="my-5" />
</PageWrapper>
</template>
<script lang="ts" setup>
import { BasicForm, FormSchema, useForm } from '@/components/Form';
import { PageWrapper } from '@/components/Page';
const schemas: FormSchema[] = [
{
field: 'field2',
component: "ApiSelect",
label: '字段1',
colProps: {
span: 8,
},
componentProps: {
resultField:"list.a",
api: ()=>{
return new Promise((resolve)=>{
resolve({
list:{
a:[{roleName:"aa",roleValue:"aa"},{roleName:"bb",roleValue:"bb"}]
}
})
})
},
labelField: 'roleName',
valueField: 'roleValue',
},
},
];
const [register] = useForm({
labelWidth: 120,
schemas,
});
</script> 由于 resultfield的存在,所以这段代码是能够正常渲染的,但是目前却报错 对象字面量只能指定已知属性,并且“list”不在类型“OptionsItem[] | PromiseLike<OptionsItem[]>”中。 看了下源码,这部分主要是用到 lodash 的 get 从object中拿到object的嵌套数据。因此改成这种recordable 这种类型应该是符合要求 |
其实只需要把自身的api结果重现map一下就可以了
|
我理解你的意思,但是您的这种写法相当于否定了resultField 的存在的意义。在你目前这种写法下面,只有把resultField删掉才能够正常回显 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
懂你的意思了,稍微简化一下吧
PropType<(arg?: any) => Promise<OptionsItem[] | Recordable>>
okok |
prop中存在resultField 这种支持xx.xx.xx类型。那么api的返回值应该包含 recordbale 类型