简体   繁体   English

如何在 WebStorm 中显示推断的 TypeScript 类型?

[英]How to show inferred TypeScript type in WebStorm?

In VS2012, you can hover over a typescript variable and it will show you the inferred type.在 VS2012 中,您可以在 typescript 变量上使用 hover,它会显示推断的类型。 Is there a similar feature in webstorm? webstorm中是否有类似的功能?

Although not perfect.虽然不完美。 Press the Ctrl key (or ⌘ Cmd on macOS) and hover over a variable with the mouse to kick in the inference logic in webstorm:使用鼠标在变量上按Ctrl键(或⌘ Cmd在 macOS 上)和 hover 以启动 webstorm 中的推理逻辑:

在此处输入图像描述

Assuming the cursor is already on the variable the best way is:假设 cursor 已经在变量上,最好的方法是:

  1. Ctrl + Shift + P Ctrl + Shift + P
  2. Return返回

Starting from WS2017.2 Ctrl (Cmd) + Hover shows inferred type.WS2017.2开始Ctrl (Cmd) + Hover显示推断类型。

Also you can try Quick Documentation : Ctrl + Q ( F1 for OS X )您也可以尝试快速文档Ctrl + QF1 for OS X)

Updated: in 2020.1 it will work as a part of the quick documentation and it works on hover if Preferences > EditoGeneral > Show quick documentation on mouse move is checked更新:在 2020.1 中,它将作为快速文档的一部分工作,并且如果选中Preferences > EditoGeneral > Show quick documentation on mouse move ,则它适用于 hover

Late to the party, and not sure when this came out, but there is a setting:派对迟到了,不知道什么时候出来的,但有一个设置:

Show quick documentation on mouse move. Delay: [500] ms

Where delay is editable.延迟是可编辑的。

You can get to it by你可以通过

File -> Settings -> Editor/General -> #Other / Show quick documentation on mouse move

Works similar to VS工作类似于 VS

Depending on the context, there are different ways to get type information.根据上下文,有不同的方法来获取类型信息。 (Shortcuts for OS X) (OS X 的快捷方式)

  1. View > Expression Type ⌘⇧P : shows a popup View > Expression Type ⌘⇧P :显示一个弹出窗口
  2. Navigate > Type Declaration ⌘⇧B : navigates in the editor导航 > 类型声明⌘⇧B :在编辑器中导航
  3. If 2. does not help, I do Navigate > Declaration ⌘B and then 2.如果 2. 没有帮助,我执行Navigate > Declaration ⌘B然后 2.
  4. View > Quick Definition ⌥Space (or ⌘Y )查看 > 快速定义⌥Space (或⌘Y
  5. View > Parameter Info ⌘P : shows a popup with the declaration of a function parameter View > Parameter Info ⌘P :显示一个带有 function 参数声明的弹出窗口

As an addition to hovering to see the type, since version 2020.3 you can go to作为悬停查看类型的补充,从 2020.3 版本开始,您可以 go 到
Settings -> Editor -> Inlay Hints -> TypeScript -> Type annotations
and check all the boxes, to see the type interference right away in your IDE:并选中所有框,立即查看 IDE 中的类型干扰:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM