microsoft / microsoft/TypeScript

Type cast should try to remove readonly modifier

Aperta
#36,404 2 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

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)

Playground Link: http://www.typescriptlang.org/play/index.html?target=99&ts=3.8.0-dev.20200123&ssl=1&ssc=1&pln=6&pc=1#code/BQbQDAugBAhgzlcECUsEDsCuBbARgUwCcQIBuAKFEjUUlXikPxgBMB7dAGwE8os8iJCgHphUAIIIALgAt8UfAA8ADjHRwAlhyhsAZrWgMAxhzhTKSGk1YceB+hhwFiZKKIWFCbQheoNr7Fy8SA6MzIF2-M5C5EA

Related Issues:

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo gli esempi di cast di tuple readonly nel TypeScript Playground o con TypeScript 3.7.x-dev.20200123, quindi segui i controlli del compilatore relativi a insufficient-overlap e all'assegnabilità di readonly. Il lavoro è completato quando il cast della tupla readonly a number[] ha esito positivo come previsto senza richiedere un cast intermedio a unknown, mentre i controlli di sicurezza esistenti rimangono intatti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.