【发布时间】:2018-04-23 17:24:38
【问题描述】:
我有一个非常简单的问题,关于给对象一个带有流的类型,这里是一个代码示例:
type Test = {
a: string
}
const t = {
test_object1: {
a: 'foo'
},
test_object2: {
a: 'bar'
}
};
如果 Test_object 是对象中的 self,我如何将它们添加到我的 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'
}
};
但没有一个有效。
【问题讨论】:
-
要设置内联注释,您需要在值周围加上括号:
({a: 'foo'} :Test)
标签: javascript flowtype