user1271930
user1271930

Reputation: 341

(vscode) How to make Visual Code to show errors on a situation like JSON.Stringify?

Since JSON.Stringify isn't valid JS it would nice to have VScode to show error or perhaps correct automatically it into JSON.stringify.

Question is that why doesn't it do it already? And how to make it happen? I believe there could be a lot of similar cases.

Upvotes: 1

Views: 1573

Answers (1)

Matt Bierner
Matt Bierner

Reputation: 65213

Try enabling TypeScript's semantic checking in your javascript file. The easiest way to do this is by adding // @ts-check to the top of your js file:

// @ts-check

JSON.Stringify([])

enter image description here

You can also enable type checking in your entire project by setting:

"javascript.implicitProjectConfig.checkJs": true

in your VSCode settings

Here's the full documentation on ts-check: https://code.visualstudio.com/docs/languages/javascript#_type-checking-and-quick-fixes-for-javascript-files

Upvotes: 3

Related Questions