【发布时间】:2021-07-26 15:19:26
【问题描述】:
如何设置响应变量的类型?
import axios from 'axios'
function postVueX (commit: (mutation: string, data: unknown) => void,
dispatch: (mutation: string, data: string, options?: { root: boolean }) => void,
url: string,
data: unknown,
mutation: string,
emptyResult: unknown,
method: () => void): Promise<void> {
return Promise.resolve()
.then(() => {
return axios.post(url, data)
})
.then(response => {
if (response) {
if (mutation) {
commit(mutation, response.data)
}
if (method) {
method(response.data)
}
}
}).catch(e => {
if (mutation) {
commit(mutation, emptyResult)
}
dispatch('notify/error', e.response.data.message, {
root: true
})
})
}
linter 在 catch 中给了我这个错误:
不安全的成员访问 .response 对 any 值。
【问题讨论】:
-
vm 是从哪里来的?请提供一个最低限度的可重现示例。
标签: typescript vue.js