alovajs / alova

Workflow-Streamlined next-generation request tools. Extremely streamline API integration workflow, just one step
https://alova.js.org
MIT License
2.97k stars 109 forks source link

[Bug]: 请问关于 `useForm` 的解构出 `form` 的类型any是正确的? #485

Closed MeetinaXD closed 4 months ago

MeetinaXD commented 4 months ago

Discussed in https://github.com/orgs/alovajs/discussions/480

Originally posted by **Skiyee** July 29, 2024 请问能否让解构出的 form 能不能与 initialForm 同类型?

这是否是一个 Bug?

这个问题是否已经存在?

Alova 版本

3.0.2

前端框架

Vue

问题描述

指定 initialData 类型时,handler 传入的 form 参数类型包含了 undefined

期望的表现

handler 传入的 form 参数类型与 initialData 一致。

JOU-amjs commented 4 months ago

没有复现你的问题,以下是我随便写的示例,alova@3.0.4

alova实例

export const alovaInst = createAlova({
  statesHook: VueHook,
  requestAdapter: adapterFetch(),
  responded: {
    onSuccess(response) {
      return response.json();
    }
  }
})

method和调用代码

const testMethod = (data: any) => alovaInst.Post<{code: number, data: string[]}>('/test', data)
const { data, form, loading } = useForm(form => testMethod(form), {
  initialForm: {
    username: 'admin',
    password: '123456'
  }
});
const { data, loading } = usePagination((page, size) => testMethod({}), {
  data: (data) => data.data,
  total: (data) => data.code
})

useForm类型提示如下: image

image

usePagination类型提示如下: image

如果还有问题,请贴出详细的代码出来,或者提供可查看的示例

BenKids commented 1 month ago

封装request时使用了token认真拦截器,需要给createClientTokenAuthentication传入typeof VueHook类型 https://alova.js.org/zh-CN/tutorial/client/strategy/token-authentication#typescript