Description
TypeScript Version: 3.7.x-dev.201xxxxx
Search Terms: JSDoc Map generics assignment any unsafe
Code
class MyServer {
constructor () {
// new Map is Map<any, any>; cannot call Map constructor with new Map<string, string[]>
/** @type {Map<string, string[]>} */
this.functions = new Map()
}
}
const myServer = new MyServer()
myServer.functions.get('foo')
Expected behavior:
Expected to be able to say what the Map contains when creating a new map. In typescript you can do new Map<string, string[]>()
but theres no explicit generic parameter function invocation syntax for JSDoc
Actual behavior:
The type Map<any, any>
exists. This fails the eslint rule of no-unsafe-assignment
and this fails the no-any
rule of tslint etc.
Note that doing something similar for arrays works because there's a special case inference for []
and it also works for Set
because the constructor is defined differently and it has generic inference in the initialization statement.
Related Issues: Yes, in eslint typescript-eslint/typescript-eslint#2109