我正在使用类似脚本创建一个类,该类具有ES6(ECMAscript 2016)Map的属性,如下所示:
class Item {
configs: ????;
constructor () {
this.configs = new Map();
}
}
Run Code Online (Sandbox Code Playgroud)
如何在打字稿中声明ES6 Map类型?
如何将这些类序列化为JSON?
从下面的示例中可以看出,JSON.stringify()没有序列化对象Cache_Backend_LocalStorage_Tag内部的列表Cache_Backend_LocalStorage_TagThree.
我错过了什么?
interface Cache_Backend_LocalStorage_Tag_Interface {
_tag : string;
_keys : string[];
}
class Cache_Backend_LocalStorage_Tag implements Cache_Backend_LocalStorage_Tag_Interface {
public _tag : string;
public _keys : string[];
constructor(tag : string) {
this._tag = tag;
this._keys = [];
}
public add(key : string) : void {
this._keys.push(key);
}
public remove(key : string): boolean {
// Get the index of the key
var index = this._keys.indexOf(key, 0);
// Check if we found the keys index
if (index …Run Code Online (Sandbox Code Playgroud) 我在c#中有字典对象.但我需要迁移到打字稿.我是打字稿的新手.我真的不知道,如何在打字稿中使用字典.
C#:
LengthsByCountry = new Dictionary<string, int>
{
{"AD", 24}, {"AL", 28}, {"AT", 20}, {"BA", 20},
{"BE", 16}, {"BG", 22}, {"CH", 21}, {"CY", 28},
{"CZ", 24}, {"DE", 22}, {"DK", 18}, {"EE", 20},
{"ES", 24}, {"FI", 18}, {"FO", 18}, {"FR", 27},
{"GB", 22}, {"GE", 22}, {"GI", 23}, {"GL", 18},
{"GR", 27}, {"HR", 21}, {"HU", 28}, {"IE", 22},
{"IL", 23}, {"IS", 26}, {"IT", 27}, {"LB", 28},
{"LI", 21}, {"LT", 20}, {"LU", 20}, {"LV", 21},
{"MC", 27}, {"ME", 22}, {"MK", 19}, {"MT", 31}, …Run Code Online (Sandbox Code Playgroud) 我想为这样的json结构声明一个TypeScript接口:
{
404: function() { alert( "page not found" ); },
400 : function() {...}
}Run Code Online (Sandbox Code Playgroud)
键是数字,值是函数,你知道如何在TypeScript中声明这样的数据约束的接口吗?
是否可以在angular 2 Map <String,List <String >>中创建?