是这样的,我这里有一个API生成器,通过配置的传入,最后得到一个Model对象,通过调用来执行request。
type IActionType = {
POST?: Record<any, any>,
GET?: Record<any, any>,
OTHERS?: Record<any, any>
}
const _actionType: IActionType = {
POST: {
rules_grid: "/rulesSetting/grid",
rules_export: "/rulesSetting/export",
rules_add: "/rulesSetting/rules_add",
rules_update: "/rulesSetting/rules_update",
rules_del: "/rulesSetting/rules_del",
rules_preview: "/rulesSetting/rules_preview",
rules_preview_batch: "/rulesSetting/rules_preview_batch",
},
GET: {
rules_getTreeOrg: "/rulesSetting/getTreeOrg",
},
}
然后是生成器
const GenerateService = <T = any>(ActionType: IActionType): T => {
// 对配置进行处理,_methods 就是扁平化之后的 API 对象
return _methods
}
很明显如果这样写的话,编辑器并不会提示,而且也没有写 TS 的必要,全是 any
根本没用。
希望大佬帮帮我 GenerateService
这个函数的返回类型该怎么写。