从TypeScript中的自定义变量添加项

从TypeScript中的自定义变量添加项,typescript,Typescript,我定义了这个接口: interface ICommand { regexp: RegExp; callback: Function; } interface ICommandList { [Phrae: string] : ICommand; } 并将变量定义为: namespace CORE{ export let commands: ICommandList; // (?: | ) non counting group, not to be consider in

我定义了这个接口:

interface ICommand {
   regexp: RegExp;
   callback: Function;
}

interface ICommandList {
   [Phrae: string] : ICommand; 
}
并将变量定义为:

namespace CORE{

export let commands: ICommandList;

// (?: | ) non counting group, not to be consider in params
// ( | )? existing or non existing it is the sam impact (one or zero) (? after the reg)
commands = {
   'test': {
         regexp: /^What is your (?:first|family) name (man|guy)$/,   
         callback: (...parameters:string[])=>alert('my name is: '+parameters[1]) //itemsIdentification,
   },

   'items identification': {
         regexp: /^(What is|What's|Could you please tell me|Could you please give me)?\s?(the)?\s?meaning of (TF|FFS|SF|SHF|FF|Tube Film|Shrink Film|Stretch Hood|Stretch Hood Film|Flat Film)$/,
         callback: (x:string)=>alert('hi 1'+x) //itemsIdentification,
   },

   'ML SoH': {
         regexp: /^(What is|What's|Could you please tell me|Could you please give me) the (stock|inventory) of ML$/,
         callback: ()=>alert('hi 2') //mlSOH,
   },

    'Report stock on hand': {
         regexp: /^(What is|What's) (our|the) (stock|inventory|SoH) of (TF|FFS|SF|SHF|FF|Tube Film|Shrink Film|Stretch Hood|Stretch Hood Film|Flat Film)$/,
         callback: ()=>alert('hi 3') //SoH,
        },

     'Basic Mathematical Opertions': {
               // ?\s? can be used instead of space, also could use /i instead of $/,
                regexp: /^(What is|What's|Calculate|How much is) ([\w.]+) (\+|and|plus|\-|less|minus|\*|\x|by|multiplied by|\/|over|divided by) ([\w.]+)$/,
                callback: ()=>alert('hi 4') //math,
              },
  };
}
我想在其他文件中为这个变量
添加更多的项目,所以我用这个文件写了另一个文件:

namespace CORE{
    commands += {
        'test2': {
         regexp: /^What is your (?:first|family) name (man|guy)$/,   
         callback: (...parameters:string[])=>alert('my name is: '+parameters[1]) //itemsIdentification,
   }
    };

}
但它给了我如下所示的错误,我的问题是: 如何为此变量添加更多项


您可以使用属性分配:

commands["test2"] = {
    regexp: /^What is your (?:first|family) name (man|guy)$/,
    callback: (...parameters: string[]) => alert('my name is: ' + parameters[1]) //itemsIdentification,
};

谢谢,成功了。在接受你的答案之前,我将稍等片刻,也许会得到一些其他答案,使我能够以一种更简单的方式添加许多行。