Is there a key bind for Visual Studio code to annotate a type in typescript

Viewed 336

For example, let's say I have the following code

const foo = "this is foo";

I would like to click on foo and press a key to annotate a type

const foo: string = "this is foo";

Visual studio code already knows the type, because is there when you hover over it. How would I make a key bind?

1 Answers

You can auto-add types by hovering over the variable and clicking Quick fix → infer parameter types from usage. The keyboard shortcut for this is ⌘ + ., then ↵.

VSCode already displaying the correct type out of the box means that typescript is inferring it for you. Adding the same declaration again would just add to the word count.

Related