在 Flow 中定义由其他对象类型组成的对象

Defining an object consisting of other object types in Flow

我有一个看起来像这样的对象:

const myObject = {
  a: {
    id: 'abc'
  },
  b: {
    id: 'def'
  },
  c: {
    id: 'ghi'
  },
}

a、b 和 c 都具有相同的结构,所以我想为它们定义一个类型(下面的 abcType),并确保 myObject 由这些类型组成。

所以基本上:

type abcType = {
  id: String
}

type myObjectType = {
  [whateverKey]: abcType
  // ^^ Dummy code, this doesn’t actually work
}

但是我似乎找不到在 Flow 中定义它的正确方法。有人 运行 遇到同样的问题吗?

type abcType = {
  id: string // lower-case 's'
}

type myObjectType = {
  [string]: abcType // 'string' type for the object keys.
};

const myObject: myObjectType = {
  a: {
    id: 'abc'
  },
  b: {
    id: 'def'
  },
  c: {
    id: 'ghi'
  },
}

应有尽有。