Below is the code snippet:
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);
}
}
An error occurs during ES5 compilation:
ERROR TypeError: Constructor Map requires 'new'
This code is used as follows:
public registryLayers = new ExtendedMap<number, any>();
Here is a snippet with 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");