[英]Redux Toolkit w TypeScript: How can I unwrap the type of AsyncThunk
I hava a action called getIndexingConfig
我有一个名为
getIndexingConfig
的操作
export const getIndexingConfig = createAsyncThunk(
"settings/getIndexingConfig",
async () => {
const {
indexingConfiguration,
groupIndexingConfiguration
} = await sdkClient.getIndexingConfiguration().promise();
return {
indexingMode: indexingConfiguration?.thingIndexingMode,
groupIndexingMode: groupIndexingConfiguration?.thingGroupIndexingMode
};
}
);
The type of it is, according to TS compiler根据 TS 编译器,它的类型是
const getIndexingConfig: AsyncThunk<
{
indexingMode: string | undefined;
groupIndexingMode: string | undefined;
},
void,
{}
>;
I wonder how I can get the return value's type from it.我想知道如何从中获取返回值的类型。 ie
IE
{
indexingMode: string | undefined;
groupIndexingMode: string | undefined;
}
I try to use ReturnType<typeof getIndexingConfig>
but it doesn't seem to unwrap the thunk to give me the return value's type.我尝试使用
ReturnType<typeof getIndexingConfig>
但它似乎没有打开 thunk 来给我返回值的类型。
export type ITSUnpackedPromiseLike<T> =
T extends ITSResolvable<infer U> ? U :
T
;
ITSUnpackedPromiseLike<ReturnType<typeof getIndexingConfig>>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.