【问题标题】:How do we get nested object type in typescript我们如何在打字稿中获得嵌套对象类型
【发布时间】:2020-03-07 07:08:09
【问题描述】:

我有以下打字稿界面:

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

我想访问如何获得它的选项。 我尝试了下面的方法,但它对我不起作用

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

【问题讨论】:

  • “它不起作用” 因为?错误或错误结果是什么?

标签: typescript react-native graphql relay


【解决方案1】:

我不知道你的 sn-p 中的 ScreenQuery 是什么,但如果 UserInfo 确实是一个有效的接口 (Playground link):

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

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

【讨论】:

    猜你喜欢
    • 2020-11-30
    • 2021-12-06
    • 2018-02-22
    • 1970-01-01
    • 1970-01-01
    • 2019-07-25
    • 1970-01-01
    • 1970-01-01
    • 2020-08-18
    相关资源
    最近更新 更多