TypeScript Objects as Dictionary types as in C#

前端 未结 6 745
春和景丽
春和景丽 2020-11-27 09:39

I have some JavaScript code that uses objects as dictionaries; for example a \'person\' object will hold a some personal details keyed off the email address.



        
6条回答
  •  爱一瞬间的悲伤
    2020-11-27 09:59

    You can use templated interfaces like this:

    interface Map {
        [K: string]: T;
    }
    
    let dict: Map = {};
    dict["one"] = 1;
    

提交回复
热议问题