我们如何在打字稿中获取嵌套对象类型

时间:2019-11-11 15:12:59

标签: typescript react-native graphql relay

我有以下打字稿界面:

UserInfo: {
     user: {
        options: ReadonlyArray<{
            values: ReadonlyArray<{
                value: string | null;
            }
        }
    }

我想访问选项我如何获得它。 我尝试过如下操作,但对我不起作用

type options = ScreenQuery["UserInfo"]["user"]["options"];

1 个答案:

答案 0 :(得分:0)

我不知道您的代码段中的ScreenQuery是什么,但是如果UserInfo确实是一个接口,则可以使用(Playground link):

interface UserInfo {
  user: {
    options: ReadonlyArray<{
      values: ReadonlyArray<{
        value: string | null;
      }>
    }>
  }
}

type options = UserInfo['user']['options'];