-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Index key accessed nullable index type is not narrowed from nullable #12636
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
Comments
This is actually a little iffy - despite how we'd like to think about it, there's not anything that really ties |
@DanielRosenwasser though it does ties to interface S {
hello: any;
}
interface R {
[i: string]: S;
}
function f<K extends keyof R>(p: K) {
let r: R = {};
if (r[p]) {
r[p].hello // No error
}
} |
Aside from not supporting narrowing with element access expressions (which is tracked by #10530), we would have to introduce a new type operator that records the fact that a truthy check has been performed on some generic type. For example, given a However, introducing new type operators is not a trivial matter, and I'm not sure it is worth the effort in this particular scenario. |
Removing the type
undefined
fromS | undefined
fixes the error and also theif
check is no longer required.The text was updated successfully, but these errors were encountered: