Flow:声明嵌套对象的类型

时间:2017-11-10 13:07:59

标签: javascript flowtype

我有一个非常简单的问题,即给出一个带有流到对象的类型,这里是一个代码示例:

type Test = {
  a: string
}

const t = {
  test_object1: {
    a: 'foo'
  },
  test_object2: {
    a: 'bar'
  }
};

如果将测试类型添加到 test_object 中,如果它们在对象中是自我的话,我该如何添加?

我试过了:

const t = {
  test_object1: {
    a: 'foo'
  } : Test,
  test_object2: {
    a: 'bar'
  } : Test
};

const t = {
  test_object1<Test>: {
    a: 'foo'
  },
  test_object2<Test>: {
    a: 'bar'
  }
};

但都没有。

2 个答案:

答案 0 :(得分:0)

我认为这有效:

<website-information info="@(new WebsiteContext {
                            Version = new Version(1, 3),
                            CopyrightYear = "1638",
                            Approved = true,
                            TagsToShow = 131 })" />

```

来源:https://flow.org/en/docs/types/objects/#toc-object-type-syntax

答案 1 :(得分:-1)

你必须输入整个对象,我不认为你可以做&#34;嵌套&#34;打字:

const t = { ... } : { test_object1: Test }
相关问题