microsoft / microsoft/TypeScript
--noImplicitAny codefixes infer anonymous object types despite appropriate interfaces in (or out of) scope
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.3.0-dev.20181212
Search Terms: noimplicitany infer code fix codefix quick suggested
Code
interface IBox {
x: number;
y: number;
}
const shiftBox = (box) => {
box.x += 1;
box.y += 1;
}
const box = {
x: 0,
y: 0,
};
shiftBox(box);
Expected behavior:
--noImplicitAny suggested fix on the box parameter:
const shiftBox = (box: IBox) =>
Actual behavior:
const shiftBox = (box: { x: any; y: any; }) => {
Related Issues: #13243 (parent tracking quick fixes) and #15114 (discussion on inference difficulties)
If there is an interface available that can satisfy an inferred type in a --noImplicitAny code fix, can we use that? Perhaps with an ordering of possibilities like:
- Interfaces already available in the file, by how small they are
- User-defined interfaces that could be imported, by how distant the file is
- Module types already imported in a user file, by how distant the nearest import is
...where, if multiple interfaces could satisfy the best possibility of those three, we choose the one with the fewest fields?
In code bases that don't explicitly type when unnecessary (e.g. : IBox for variables), I'm finding the --noImplicitAny fixes to be a bit useless for anything other than primitives.
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
Beginnen Sie mit dem bereitgestellten TypeScript-Beispiel und reproduzieren Sie die Ausgabe des --noImplicitAny-Codefixes. Lesen Sie die Diskussion in den verwandten Issues #13243 und #15114, um die vorgeschlagenen Regeln zur Interface-Auswahl zu verstehen; als erledigt gilt die Aufgabe, wenn ein kompatibles verfügbares Interface wie IBox gegenüber einem anonymen Objekttyp bevorzugt wird, ohne andere Codefix-Fälle zu beeinträchtigen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 32/100