arrays - 具有不同形状对象的元组
问题描述
我需要将对象推送到数组中,但对象具有不同的形状。像这样的东西:
const credentials = [
{
service: 'Service1',
email: 'test@test.com',
key: 25
},
{
service: 'Service2',
ip: '192.168.1.2',
name: 'Person',
url: 'test.com'
},
]
我尝试使用 Tuple,但是当我尝试访问属性时收到错误消息。
编辑:问题不一定是推送对象,是访问,基本上,问题在于类型定义
解决方案
推荐阅读
- nuxt.js - 使用 Nuxt JS “运行生成”后没有创建 Content-Security-Policy HTTP 标头
- javascript - 将字符串中的“he”替换为“she”(与“the”重叠)
- javascript - 在 JavaScript 上对数组元素进行排序
- python - 如何在 Windows 中设置 OS 密钥以便稍后在 Python 中访问它?
- python - 试图找到具有最大第一个元素的数组?
- sql - 为过程 PLSQL 创建自己的异常
- c# - 在 C# 中更新矩阵类实例的值
- javascript - 在 React 中为视频元素设置音量
- python - Seaborn 分裂小提琴情节未正确分裂
- python - 具有多个特征的递归神经网络中的错误