How to define Typescript Map of key value pair. where key is a number and value is an array of objects

后端 未结 3 2101
广开言路
广开言路 2021-01-30 20:41

In my angular2 app i want to create a map which takes a number as key and returns an array of objects. I am currently implementing in following way but no luck. How should i imp

3条回答
  •  庸人自扰
    2021-01-30 21:02

    The most simple way is to use Record type Record

    interface productDetails {
       productId : number , 
       price : number , 
       discount : number
    };
    
    const myVar : Record = {
       1: {
           productId : number , 
           price : number , 
           discount : number
       }
    }
    

提交回复
热议问题