microsoft / microsoft/TypeScript
JSDoc missing syntax for `new Map<string, string>()`
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere das JavaScript-Beispiel im verlinkten TypeScript Playground und vergleiche das aktuelle Ergebnis von Map<any, any> mit der erwarteten typisierten Zuweisung. Überprüfe, wie JSDoc-Typen generische Konstruktoraufrufe darstellen, und ziehe dazu das zugehörige typescript-eslint-Issue als Kontext heran. Als abgeschlossen gilt die Aufgabe, wenn eine unterstützte Syntax definiert ist und das Beispiel nicht mehr den unsicheren any-Typ inferiert.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 30/100