VS 代码如何在鼠标悬停时显示完整的打字稿定义 [英] VS code how to show full typescript definition on mouse hover

查看:77
本文介绍了VS 代码如何在鼠标悬停时显示完整的打字稿定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 React 项目从 jsx 转换为 tsx 文件.

I'm converting React project from jsx to tsx files.

我需要一个常量类型的完整预览:

i need full preview of types of one constant:

const canvasProps = {
  setPorts,
  setBoxes,
  setLines,
  selected,
  setSelected,
  actionState,
  setActionState,
  ... // and more
};

将鼠标悬停在 canvasProps 上时,我会看到预览:

on hover on canvasProps I get the preview:

const canvasProps: {
    setPorts: React.Dispatch<React.SetStateAction<{
        shape: string;
        id: string;
        name: string;
        port: portType;
        ref: any;
    }[]>>;
    setBoxes: React.Dispatch<React.SetStateAction<BoxType[]>>;
    ... 13 more ...;
    toggleFlowVisibility: (flow: any) => void;
}

我需要获取这个常量的完整类型定义,这意味着查看额外的 13 种类型.

I need to get the full type definition of this constant, which means see the extra 13 types.

(为什么我需要这个?我需要声明 React.Context 的属性,它依赖于尚未声明的函数(在函数组件内部))

(why I need this? I need to declare the properties of React.Context, which depends on functions that have not declared yet (inside a function component) )

那么我可以在不努力的情况下获得完整的类型定义吗?

so I do I get the full type definition without working hard?

推荐答案

Setting "noErrorTruncation": true,正如在上一个答案中提出的那样,不适用于这个问题被问到了.

Setting "noErrorTruncation": true, as proposed in the previous answer, does not work for this question as asked.

一个真正有效的快速修复将是......一个更具攻击性的解决方案;p

A quick fix that actually does work would be… a more offensive solution ;p

从打开开始

<Microsoft VS Code install folder>/resources/app/extensions/node_modules/typescript/lib/tsserver.js

并且,在第 13471 行附近(到目前为止),更改:

And, around line 13471 (so far), change:

ts.defaultMaximumTruncationLength = 160

更高的东西,比如

ts.defaultMaximumTruncationLength = 800

这会让你得到你所期待的.一个不错的 800 个字符长最大类型定义悬停.当然,您可以根据需要对其进行自定义.

This will get you what you are waiting for. A nice 800 chars long max type definition on hover. You can, of course, custom this as much as you want.

这可能无法维护,因为您需要在每次 Visual Studio Code 更新后再次执行此操作,但它运行良好,您最终会在悬停时获得完整类型.

This might not be maintainable as you will need to do it again after every Visual Studio Code update, but it works just fine, and you'll finally get your full type on hover.

请注意,您需要重新启动 tsServer.在 Visual Studio Code 中这样做:

Note that you'll need to restart your tsServer. To do so in Visual Studio Code:

  • ctrl + shift + P
  • 输入重启ts服务器
  • 回车.
  • Press ctrl + shift + P
  • Type restart ts server
  • Press enter.

等待几秒钟,它相当快.

wait a couple seconds, it's fairly quick.

这篇关于VS 代码如何在鼠标悬停时显示完整的打字稿定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆