microsoft / microsoft/TypeScript
Fast path opportunity in `checkVariableLikeDeclaration`
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
I noticed that for this code:
class A {
state = { foo: "foo", bar: 42 };
}
checkVariableLikeDeclaration calls checkTypeAssignableToAndOptionallyElaborate here:
https://github.dev/microsoft/TypeScript/blob/e9868e96e87996df46a13b4323866acc639e71ce/src/compiler/checker.ts#L40690
This is likely redundant for cases without a declared type as it's guaranteed that this has to return true. I thought at first that this would rely on a fast past based on the type.id but it seems that those types have different ids (perhaps one is fresh while the other one isn't or something?).
I'm happy to explore this optimization. But perhaps you'd have some preferences as to at which level this should be applied?
cc @jakebailey
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
Beginne in src/compiler/checker.ts bei checkVariableLikeDeclaration und dessen Aufruf von checkTypeAssignableToAndOptionallyElaborate. Verwende das Klassenfeldbeispiel aus dem Issue, um zu untersuchen, ob die Prüfung redundant ist, wenn kein deklarierter Typ vorhanden ist, und ob die unterschiedlichen type IDs relevant sind. Bestätige das Verhalten der Optimierung und miss, ob sie diesen Pfad verbessert.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers, performance
- Issue-Typ
- Refactoring
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100