microsoft / microsoft/TypeScript
Diagnostic about "left-hand side of a 'for...in' statement" type is out of date
Personne n'a encore pris cette issue.
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.3k
- Merge moyen
- 2 j 4 h
- PR mergées (30 j)
- 132
Description
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'."
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par reproduire l’exemple for...in fourni et comparez le diagnostic pour number avec le cas accepté keyof Foo. L’issue n’indique aucun fichier source ni aucun test ; localisez le diagnostic du vérificateur de types et ses tests existants, puis mettez à jour la formulation et vérifiez que les cas incorrect et valide sont couverts.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- typescript
- Domaine
- compilers
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 38/100