【发布时间】:2020-12-01 07:16:47
【问题描述】:
我正在尝试根据传递给它的参数的数量和类型来创建动态数量的对象
我的一般骨架是这样的
interface KeyValue {
key: string;
value: string;
}
class CreateObjects {
//example of how im tyring to make the objects look
propertyTest: KeyValue = {key: 'Example', value: 'Object'};
//function that creates objects like above but does so dynamically with unique and iterative property names
methodTest: ([dynamic number of arguments]){
[dynamicproperty1]: KeyValue = {key: 'Example', value: argument};
}
我不知道这一切是否都错了,但基本上我不知道会通过多少个参数。它可以是无、1 或 50+。该参数仅更改“值”键/值对,并且该对象需要可作为其他函数的参数访问。
我觉得我错过了一些关于创建对象的基本知识,这使得这项任务变得如此困难
谢谢
【问题讨论】:
标签: typescript class object interface properties