microsoft / microsoft/TypeScript
Diagnostic about "left-hand side of a 'for...in' statement" type is out of date
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 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'."
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the provided for...in example and comparing the diagnostic for number with the accepted keyof Foo case. The issue names no source file or test; locate the type-checker diagnostic and its existing tests, then update the wording and verify that the incorrect and valid cases are covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100