我正在使用React和Axios。最近,我在Axios上创建了一个自定义配置,如下所示:
import $axios from 'helpers/axiosInstance'
$axios.get('/customers', { handlerEnabled: false })
字符串
但最终的TS编译:
类型“{ handlerEnabled:boolean; }”的参数不可分配给类型“AxiosRequestConfig”的参数。对象文本只能指定已知属性,并且“handlerEnabled”在类型“AxiosRequestConfig”中不存在。
如何在AxiosRequestConfig
上分配新类型?类似于axios<AxiosRequestConfig & newType>
我不想使用像.d.ts
这样的旧方法。
2条答案
按热度按时间gkn4icbw1#
通过使用typescript声明合并特性,您可以扩展任何库类型。(docs)
所以这个应该可以完成任务:
字符串
biswetbf2#
字符串