admin管理员组

文章数量:1410725

I'm using JSDoc to document my Javascript functions and add type annotations.

In Visual Studio, I am getting intellisense for these functions, which is great. However, if I use an incorrect type (e.g. an integer for a parameter annotated as a string), I don't see any kind of warning about it anywhere. I have the same problem if I use the wrong number of arguments for a function.

I've looked through all the settings in Tools > Options, but didn't see anything relevant. I also use ReSharper, but didn't see anything in R# options either.

Is there some way to get Visual Studio to show a warning?

I'm using JSDoc to document my Javascript functions and add type annotations.

In Visual Studio, I am getting intellisense for these functions, which is great. However, if I use an incorrect type (e.g. an integer for a parameter annotated as a string), I don't see any kind of warning about it anywhere. I have the same problem if I use the wrong number of arguments for a function.

I've looked through all the settings in Tools > Options, but didn't see anything relevant. I also use ReSharper, but didn't see anything in R# options either.

Is there some way to get Visual Studio to show a warning?

Share edited Sep 25, 2018 at 14:21 Cocowalla asked Sep 25, 2018 at 11:36 CocowallaCocowalla 14.4k6 gold badges75 silver badges116 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

You can also do that in Visual Studio Code, by going to Preferences > Settings and checking Javascript>Implicit Project Config-checkJs.

This should give you some basic intelliSense and mark type errors with familiar red underline.

I found a link with some answers. There are 2 ways to do this:

  1. Enable it for all Javascript files by adding a tsconfig.json to your project's root directory, with `checkJs: true"
  2. Enable it for specific Javascript files by adding // @ts-check at the start of the file

In my case however, I wanted to enable this in Razor files, which have all have a script tag at the bottom - but it seems type checking is only possible in 'pure' Javascript/Typescript files.

本文标签: javascriptHow to show warning when using functions incorrectly according to JSDocStack Overflow