[英]Typescript - ReturnType from nested arrow function
I have a type that describes an object with a nested function:我有一个描述 object 和嵌套 function 的类型:
type EntitiesGetters = {
getCategories: (state: EntitiesState) => (panelID: EntityID) => CategoryGroup;
};
and here is an example of applying this type to an object:这是将此类型应用于 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;
},
};
How can I get the type I need in GET_TYPE (which corresponds to the type "CategoryGroup")?如何在 GET_TYPE 中获取我需要的类型(对应于类型“CategoryGroup”)?
Еither correct me if I'm using the wrong approach.如果我使用了错误的方法,请纠正我。
You should be able to use the TypeScript builtin ReturnType
:您应该能够使用 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.