microsoft / microsoft/TypeScript
Diagnostic about "left-hand side of a 'for...in' statement" type is out of date
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Go
- Estrelas
- 111k
- Forks
- 14.3k
- Merge médio
- 2d 4h
- PRs com merge (30d)
- 132
Descrição
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'."
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece reproduzindo o exemplo fornecido de for...in e compare o diagnóstico para number com o caso aceito keyof Foo. A issue não indica nenhum arquivo-fonte nem teste; localize o diagnóstico do verificador de tipos e seus testes existentes, depois atualize o texto e verifique se os casos incorreto e válido estão cobertos.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- typescript
- Domínio
- compilers
- Tipo de issue
- Bug
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 38/100