microsoft / microsoft/TypeScript
Type cast should try to remove readonly modifier
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
The compiler should try to use mutable versions of readonly tuples when couldn't cast readonly tuples to mutable arrays mainly for usability of as const. The performance impact of this would be a little because the condition when this check runs is limited.
TypeScript Version: 3.7.x-dev.20200123
Search Terms:
Code
([0] as [0]) as number[];
([0] as [0]) as readonly number[];
// As the expansion of [0] as const
([0] as readonly [0]) as number[]; // error
([0] as readonly [0]) as readonly number[];
Expected behavior:
pass
Actual behavior:
Conversion of type 'readonly [0]' to type 'number[]' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
The type 'readonly [0]' is 'readonly' and cannot be assigned to the mutable type 'number[]'.(2352)
Related Issues:
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 damit, die Beispiele für readonly-Tuple-Casts im TypeScript Playground oder mit TypeScript 3.7.x-dev.20200123 zu reproduzieren, und verfolge anschließend die Prüfungen des Compilers auf insufficient-overlap und readonly-Zuweisbarkeit. Als abgeschlossen gilt die Aufgabe, wenn der readonly-Tuple-Cast zu number[] wie erwartet erfolgreich ist, ohne einen zwischengeschalteten unknown-Cast zu erfordern, während die bestehenden Sicherheitsprüfungen intakt bleiben.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 35/100