Can't the Map of js accept a parameter? Is there any expert who can teach me?
class myMap extends Map {
constructor(props: any) {
super(props);
}
}
Can't the Map of js accept a parameter? Is there any expert who can teach me?
class myMap extends Map {
constructor(props: any) {
super(props);
}
}
The type definition of Map is...
interface MapConstructor {
new(): Map<any, any>;
new<K, V>(entries?: readonly (readonly [K, V])[] | null): Map<K, V>;
readonly prototype: Map<any, any>;
}
which gives 2 constructor functions...
new which doesn't have any parametersnew<K, V> which takes 1 parameterBoth of which return(s) an interface of Map<K, V>. Now when we are extending myMap with a non-generic Map, the constructor available is parameter-less. To be able to pass a parameter, we can write the definition of myMap as such, unless we have any other reason not to..
class myMap extends Map<string, string> {
constructor(props: any) {
super(props)
}
}
where Map<string, string> is just an example for illustration. We will have to decide upon the actual type of Map<K, V> from the context of the usecase.