Checker rejects literal bracket writes to writable static fields

Aperta
#3,631 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
csharp, typescript
Ambito
compilers

Direzione di ricerca

The bug is in the type checker's index-access assignment path, which rejects a string-literal key on a class constructor's writable static field. Start by finding where the message "is not valid for assigning to" is produced and how it handles a literal index versus a dotted member access on the same static. Done when C['value'] = 1 and this['value'] = 1 in a static block type-check the same as C.value = 1, and the reproduction from the issue passes under --strict.

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

Descrizione

class C { static value = 0; }
C['value'] = 1;

TypeScript 6.0.3 accepts this with --ignoreConfig --strict --target ES2022 --noEmit. SharpTS at 72455db66 rejects it with --no-tsconfig --strict --noEmit and reports Index type '"value"' is not valid for assigning to 'class C'.

A literal-key bracket assignment to a writable static field should be type-checked like the corresponding dotted assignment. This also affects this['value'] = 1 in a static block. Found while verifying #3621.

Lingua principale
C#
Stelle
156
Fork
4
Merge medio
16h 37m
PR unite (30g)
41

Preparare l'ambiente

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.

Altre issue di nickna/SharpTS

Tutte le issue di nickna/SharpTS

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.