Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS code how to show full typescript definition on mouse hover

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
};

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;
}

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

(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?

like image 234
Eliav Louski Avatar asked Jun 22 '20 06:06

Eliav Louski


People also ask

How do you jump to define in VS Code?

Go to Definition# Tip: You can jump to the definition with Ctrl+Click or open the definition to the side with Ctrl+Alt+Click.

How do you display results in output VS Code?

To open the Output window, on the menu bar, choose View > Output, or press Ctrl+Alt+O.

How do you show source control in VS Code?

The Source Control icon in the Activity Bar on the left will always indicate an overview of how many changes you currently have in your repository. Selecting the icon will show you the details of your current repository changes: CHANGES, STAGED CHANGES and MERGE CHANGES.


1 Answers

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

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

Start by opening

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

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

ts.defaultMaximumTruncationLength = 160

to something higher, like

ts.defaultMaximumTruncationLength = 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.

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.

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

  • Press ctrl + shift + P
  • Type restart ts server
  • Press enter.

wait a couple seconds, it's fairly quick.

like image 81
LoveriusB Avatar answered Oct 23 '22 22:10

LoveriusB