How to declare an object whose properties are of type string only using TypeScript?

前端 未结 3 813
遥遥无期
遥遥无期 2021-01-29 04:21

I have a configuration array in my component like this.

...
config: ButtonConfig[];
...
this.config.push(new ButtonConfig(...));
...

Today, I r

3条回答
  •  执念已碎
    2021-01-29 04:54

    You can do it like following:

    config: { [key:string]: ButtonConfig } = {};
    
    ...
    this.config.submitButton = new ButtonConfig(...);
    ...
    

    Here's a working stackblitz project: https://stackblitz.com/edit/angular-opc8yg

提交回复
热议问题