首页 > 解决方案 > 具有不同形状对象的元组

问题描述

我需要将对象推送到数组中,但对象具有不同的形状。像这样的东西:

const credentials = [
  {
    service: 'Service1',
    email: 'test@test.com',
    key: 25
  },
  {
    service: 'Service2',
    ip: '192.168.1.2',
    name: 'Person',
    url: 'test.com'
  },
]

我尝试使用 Tuple,但是当我尝试访问属性时收到错误消息。

编辑:问题不一定是推送对象,是访问,基本上,问题在于类型定义

标签: arraystypescriptobjecttuplestypeerror

解决方案


推荐阅读