You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In your example, the typeof operator appears in a type context (not expression context!), and you should use indexed access type foo<typeof a[0]['b']>() to get the type of a property.
My understanding is that we try parsing type arguments, we see typeof a[0].b which is initially parsed as (typeof a)[0]. The . can't follow the type though because the left side is not valid for a qualified name though, so we determine that we can't parse the type arguments and throw the work away, back-tracking and trying to parse it as a < comparison.
Activity
whzx5byb commentedon Jul 1, 2021
In your example, the
typeofoperator appears in a type context (not expression context!), and you should use indexed access typefoo<typeof a[0]['b']>()to get the type of a property.devanshj commentedon Jul 1, 2021
Umm I don't think so, if it were in a type context
typeof a.b.cwould also not work but it does.DanielRosenwasser commentedon Jul 1, 2021
Seems possibly related to #19707.
My understanding is that we try parsing type arguments, we see
typeof a[0].bwhich is initially parsed as(typeof a)[0]. The.can't follow the type though because the left side is not valid for a qualified name though, so we determine that we can't parse the type arguments and throw the work away, back-tracking and trying to parse it as a<comparison.sandersn commentedon Jul 2, 2021
I agree, this is a duplicate of #19707