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
Note that this isn't just about twoslash hints, but extends to hover tips as well. It is kind of frustratingly inconsistent (for no apparent reason, from an end-user point of view) that hovering over ["a1"] shows what type of value it's accessing, but not ["a2"]. If you want to see that type you have to assign it to a const first and hover over that.
How about number from [x: string]: number? Works similarly to how we show type parameters as T in f<T>(): void.怎么样 number from [x: string]: number ?工作方式类似于我们将类型参数显示为 T in f<T>(): void .
This seems intuitive.
While I'm not sure what's best to show, I'm a little confused that typescript shows me nothing when I encounter this situation.
Activity
RyanCavanaugh commentedon Jun 18, 2024
I'm not sure what's best here. We show
But
a2isn't a property; it's an index signature. It'd be confusing to just showhere since
"a2"is not a number.We've never had reason to show
(index signature)or whatnot here.This doesn't seem like something people commonly encounter as a problem.
fatcerberus commentedon Jun 18, 2024
Note that this isn't just about twoslash hints, but extends to hover tips as well. It is kind of frustratingly inconsistent (for no apparent reason, from an end-user point of view) that hovering over
["a1"]shows what type of value it's accessing, but not["a2"]. If you want to see that type you have to assign it to aconstfirst and hover over that.DanielRosenwasser commentedon Jun 18, 2024
How about
number from [x: string]: number? Works similarly to how we show type parameters asT in f<T>(): void.Kanade-Lu commentedon Jun 19, 2024
This seems intuitive.
While I'm not sure what's best to show, I'm a little confused that typescript shows me nothing when I encounter this situation.
kermanx commentedon Jun 19, 2024
More information: If you destruct the object, then the type will be shown:
Playground
Andarist commentedon Aug 20, 2024
There is already some support for those kinds of displays and the format is different (TS playground):
The formatting issue here is, in part, related to the fact that this index signature comes from a mapped type (TS playground):
and in part that it comes from an intersection since this doesn't work either (TS playground):
None of those works with
foo['something'].