【问题标题】:how to flow type array of objects with object keys as string and values of mixed type如何使用对象键作为字符串和混合类型的值来流动类型的对象数组
【发布时间】:2020-02-07 14:59:17
【问题描述】:

如何以对象键为字符串和混合类型的值来流动类型的对象数组?

example : [
        {"appId":13118,"id":100,"a":"hey","b":-1,"c":null,"d":0,"e":true}
]

现在我正在这样做 示例:数组

是否可以在这里定义任何可接受的类型?

【问题讨论】:

    标签: javascript flowtype


    【解决方案1】:

    您需要使用 objects as maps 的 Flow 语法。

    const example : Array<{[string] : mixed }> = [
      { "appId": 13118, "id": 100, "a": "hey", "b": -1, "c": null, "d": 0, "e": true }
    ]
    

    附带说明,在 JavaScript 中,对象键始终是字符串,因此您无需在键周围加上引号:

    const example : Array<{[string] : mixed }> = [
      { 
        appId: 13118,
        id: 100,
        a: "hey",
        b: -1,
        c: null,
        d: 0,
        e: true
      }
    ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-07
      • 1970-01-01
      • 2020-02-02
      • 1970-01-01
      • 2020-04-02
      • 1970-01-01
      • 2020-09-11
      • 2017-05-02
      相关资源
      最近更新 更多