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

问题描述 投票:0回答:1

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

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

目前,我正在这样做例如:Array

是否可以在此处定义任何可接受的类型?

javascript flowtype
1个回答
0
投票

您需要对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
  }
]
© www.soinside.com 2019 - 2024. All rights reserved.