Narrow indexing variable when type-testing indexed access expressions #45421
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
Bug Report
π Search Terms
type, inference, object, never
π Version & Regression Information
4.3.5
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
"typeof info[k]" is inferred to be "never"
But at the line 10(if typeof info[k] === "string), "typeof info[k]" was string or number.
Furthermore, after making sure the type of "info[k]" by using "if", it still remains to be "never".
And, although compiler throws an Error above, when I executed the code, it runs very well with the result below
[LOG]: "Before info Iteration:", { "userId": "asdf", "age": 11 }
[LOG]: "After info Iteration:", { "userId": "mamamama", "age": 31 }
π Expected behavior
I think "typeof info[k]" should be "string | number", not 'never'
The text was updated successfully, but these errors were encountered: