If I create a map like so: (playground)
const x = new Map();
const y = x.get("foo");
y.thisDoesntExist();
I'd expect to get an error on the last line (at least in strict mode), because I've never specified what the key and value types of new Map should be. Instead the type of the map is Map<any, any> and so I don't get any warnings. The same happens with Set<any>.
I'm in the process of porting a JavaScript project so cases like these are all over the place and it's hard to tell where types are missing.
Is there a way to configure typescript so that it warns me when I try to instantiate Sets and Maps without generics? Or at least make the generics default to Set<unknown>?
CodePudding user response:
Parameterless Map constructor has Map<any, any> return type:
interface MapConstructor {
new(): Map<any, any>;
// ...
}
Hence the noImplicitAny won't help here (the type is explicit
