我有这样的对象:
{
one: [
{
a: "some",
b: "some",
}
],
two: [
{
a: "some",
b: "some",
}
],
...
}
此示例的正确流量类型是什么?
你去吧
/* @flow */
type MyType = {
[key: string]: Array<{ a: string, b: string }>,
};
function myFunc(obj: MyType) {
return obj;
}
const myObj = {
one: [
{
a: 'some',
b: 'some',
}
],
two: [
{
a: 'some',
b: 'some',
}
],
};
const doSomething = myFunc(myObj); // No errors
在Objects as maps doc中,你会发现For objects like these, Flow provides a special kind of property, called an “indexer property.” An indexer property allows reads and writes using any key that matches the indexer key type.
有一个专用的synta:{ [user_id: number]: string }