[英]Typescript - ReturnType from nested arrow function
我有一个描述 object 和嵌套 function 的类型:
type EntitiesGetters = {
getCategories: (state: EntitiesState) => (panelID: EntityID) => CategoryGroup;
};
这是将此类型应用于 object 的示例:
export const entitiesGetters: EntitiesGetters = {
getCategories: (state) => (panelID) => {
const data = {} as GET_TYPE;
for (const key in state.categories) {
const category = state.categories[key];
if (category.entities.panel === panelID) {
data[Object.keys(data).length] = category;
}
}
return data;
},
};
如何在 GET_TYPE 中获取我需要的类型(对应于类型“CategoryGroup”)?
如果我使用了错误的方法,请纠正我。
您应该能够使用 TypeScript 内置ReturnType
:
export const entitiesGetters: EntitiesGetters = {
getCategories: (state) => (panelID) => {
const data: ReturnType<ReturnType<EntitiesGetters["getCategories"]>> = {}
// ...
return data;
},
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.