microsoft / microsoft/TypeScript
Diagnostic about "left-hand side of a 'for...in' statement" type is out of date
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
TypeScript Version: 2.1.5
Now that the left side of a 'for...in' statement is apparently allowed to be keyof the right side, the diagnostic for when the left side has the wrong type needs to be updated to account for that possibility.
(Aside: Is it intentional that the left side won't be inferred to have the keyof type because of the unsoundness described in #12314, but it is allowed to be explicitly declared as that type?)
Code
interface Foo {
x: number;
y: string;
}
function scan(f: Foo) {
let k: number;
for (k in f) { // Error: "The left-hand side of a 'for...in' statement must be of type 'string' or 'any'."
console.log(k);
}
let k2: keyof Foo;
for (k2 in f) { // No error
console.log(k2);
}
}
Expected behavior:
Something like "The index type of the right side of a 'for...in' statement must be assignable to the left side" perhaps, with details on the failure of assignability?
Actual behavior:
"The left-hand side of a 'for...in' statement must be of type 'string' or 'any'."
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo l’esempio for...in fornito e confronta la diagnostica per number con il caso accettato keyof Foo. L’issue non indica alcun file sorgente né alcun test; individua la diagnostica del type-checker e i test esistenti, quindi aggiorna la formulazione e verifica che i casi errato e valido siano coperti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100