How to show inferred TypeScript type in WebStorm?

2019-02-02 21:21发布

In VS2012, you can hover over a typescript variable and it will show you the inferred type. Is there a similar feature in webstorm?

3条回答
太酷不给撩
2楼-- · 2019-02-02 21:37

Assuming the cursor is already on the variable the best way is:

  1. Ctrl + Shift + P
  2. Return

Starting from WS2017.2 Ctrl (Cmd) + Hover shows inferred type.

Also you can try Quick Documentation: Ctrl + Q ( F1 for OS X )

查看更多
祖国的老花朵
3楼-- · 2019-02-02 21:49

Depending on the context, there are different ways to get type information. (Shortcuts for OS X)

  1. View > Expression Type ⌘⇧P: shows a popup
  2. Navigate > Type Declaration ⌘⇧B: navigates in the editor
  3. If 2. does not help, I do Navigate > Declaration ⌘B and then 2.
  4. View > Quick Definition ⌥Space (or ⌘Y)
  5. View > Parameter Info ⌘P: shows a popup with the declaration of a function parameter
查看更多
贼婆χ
4楼-- · 2019-02-02 21:56

Although not perfect. Press the Ctrl key and hover over a variable with the mouse to kick in the inference logic in webstorm :

enter image description here

查看更多
登录 后发表回答