Code is:
export class ExtendedMap<T, U> extends Map {
constructor() {
super();
}
toggle(key: T, value: U) {
if (this.has(key)) {
super.delete(key);
} else {
super.set(key, value);
}
}
has(key: T): boolean {
return super.has(key);
}
}
I get this error for ES5 compilation:
ERROR TypeError: Constructor Map requires 'new'
I'm using it like this:
public registryLayers = new ExtendedMap<number, any>();
Snippet (without TypeScript parts commented out):
/*export*/ class ExtendedMap/*<T, U>*/ extends Map {
constructor() {
super();
}
toggle(key/*: T*/, value/*: U*/) {
if (this.has(key)) {
super.delete(key);
} else {
super.set(key, value);
}
}
has(key/*: T*/)/*: boolean*/ {
return super.has(key);
}
}
/*public*/ registryLayers = new ExtendedMap/*<number, any>*/();
console.log("Worked without error");
Mapwasn't in ES5. Also note that there's no point to either the constructor or thehasoverride in your code. You can inherit both, since neither does anything new. It would also probably be best to usethisrather thansuperintoggle.Map.Symbol.species before. I should have follow your answers a long time ago