-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type guards do not work on array access expressions #11483
Comments
I'm not sure if this is intended to work, it would stand to reason since for (let i of list) {
if (typeof i === 'string') {
console.log(i.charAt(0));
}
} |
This is a duplicate of #10530 |
@mhegazy the sample doesn't compile under Nathan's PR |
well.. it did in a previous iteration. the result was all array indexes were narrowed adding high perf and memory pressure. the current iteration of the PR, only narrows strings, this seems to be less expensive. we can discuss a better implementation. |
Declined due to performance reasons. Since it should almost always be possible to write |
TypeScript Version: 2.0.3
Code
Expected behavior:
Successful compilation, since the type of
list[j]
is made clear with type guardActual behavior:
error TS2339: Property 'charAt' does not exist on type 'string | number'
The text was updated successfully, but these errors were encountered: