microsoft / microsoft/TypeScript
JSDoc missing syntax for `new Map<string, string>()`
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
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 https://github.com/typescript-eslint/typescript-eslint/issues/2109
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Reproduce el ejemplo de JavaScript en el TypeScript Playground enlazado y compara el resultado actual de Map<any, any> con la asignación tipada esperada. Revisa cómo los tipos de JSDoc representan las llamadas a constructores genéricos, usando como contexto el issue relacionado de typescript-eslint. Se considera terminado cuando se define una sintaxis compatible y el ejemplo deja de inferir un tipo any inseguro.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript, typescript
- Área
- compilers
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 30/100