microsoft / microsoft/TypeScript
JSDoc missing syntax for `new Map<string, string>()`
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riproduci l’esempio JavaScript nel TypeScript Playground collegato e confronta il risultato attuale di Map<any, any> con l’assegnazione tipizzata prevista. Esamina come i tipi JSDoc rappresentano le chiamate a costruttori generici, usando come contesto la issue correlata di typescript-eslint. Il lavoro è completato quando viene definita una sintassi supportata e l’esempio non inferisce più un tipo any non sicuro.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 30/100