Recently, I started using Typescript and encountered an issue with passing arguments to a function in Typescript. This particular function is triggered when rendering a form modal. However, I keep receiving two errors:
"Argument of type 'Promise<AxiosResponse>' is not assignable to parameter of type '(data: Record<string, unknown>) => Promise'."
"Type 'Promise<AxiosResponse>' provides no match for the signature '(data: Record<string, unknown>): Promise'."
function openModal(activity) {
const data = ref({
name: activity.name,
})
formRender.render(activity, updateActivity(activity.id,{name:data.value.name}))
}
This is the updateActivity function:
export function updateActivity(id: number, data: Record<string, unknown>) {
return http.patch(`/${id}`, { name: data.name })
}
The FormRender component:
export function FormRender<T extends Record<string, unknown>>(formName: string) {
return {
render(formAttributes: T | Record<string, unknown>, service: (data: T) => Promise<unknown>) {
dialog({
component: FormRender,
componentProps: {
formName,
formAttributes,
service
},
})
},