I am trying to create a class FooMap that extends the default TypeScript Map class by restricting the type of parameters it accepts. The reason I am extending the Map class is because I want to write methods for that class that I will be accessing from different files.
The default Map class is Map<any,any>, however the FooMap class would be similar to a Map<number,Foo> using the built-in number type and user-defined Foo type. The FooMap would only accept these key/value pairs.
My attempt to to this was by passing a map in the constructor but I feel like there is a better way to do this.
// Say Foo class is defined as
export class Foo {
id: number;
name: string;
}
Now, the FooMap class would be:
export class FooMap extends Map{
constructor(otherMap : Map<number,Foo>){
super(otherMap);
}
}
But this does not work since super() only accepts an iterable, so there must be a better way to extend the Map class.