TypeScript hashmap/dictionary interface

前端 未结 3 1358
庸人自扰
庸人自扰 2021-01-31 06:48

I\'m new to using TypeScript and I\'m trying to implement a hashmap/dictionary interface. So far I have

export interface IHash {
    [details: string] : string;
         


        
3条回答
  •  庸人自扰
    2021-01-31 07:29

    The most simple and the correct way is to use Record type Record

    const myVar : Record = {
       key1: 'val1',
       key2: 'val2',
    }
    

提交回复
热议问题