简体   繁体   English

Redux Toolkit w TypeScript:如何打开 AsyncThunk 的类型

[英]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.

相关问题 Redux Toolkit w/TypeScript:如何正确键入异步 thunk 的返回值 - Redux Toolkit w/ TypeScript: how can I properly type the return value from an async thunk 如何在 Redux Toolkit 中正确覆盖 AsyncThunk 的泛型 - How do I properly overwrite generic of AsyncThunk in Redux Toolkit TypeScript:使用 Redux 工具包的“unwrapResult”时,正确键入 AsyncThunk 的返回类型 - TypeScript: correct typing for return type of AsyncThunk when using 'unwrapResult' of Redux Toolkit 打字稿:我怎样才能解开也许<T>类型? - TypeScript: How can I unwrap the Maybe<T> type? 如何在 Redux-toolkit 的 Initialstate 中定义类型? - How can I define a type in Initialstate in Redux-toolkit? 如何使用 Redux 工具包(使用 TypeScript)解决“AsyncThunkAction”类型中缺少“属性”类型? - How do I resolve 'Property 'type' is missing in type 'AsyncThunkAction' using Redux Toolkit (with TypeScript)? typescript 中的 redux-toolkit createAction() 类型定义 - redux-toolkit createAction() type definition in typescript 如何使用 redux 工具包和 typescript 配置 redux sagas? - how to configure redux sagas with redux toolkit and typescript? Redux工具包中如何设置typescript? - How do I set up typescript in Redux toolkit? Redux 工具包打字稿——我的 PayloadAction 类型是什么? - Redux toolkit typescript -- what is my PayloadAction type?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM