3

The following JavaScript is saved into a file called test.js

iDontExist();

(this is the entire file)

VSCode doesn't show the highlights for the iDontExist function, which isn't imported or required anywhere.

How can I make VScode highlight the undefined function?

enter image description here

Note other Intellisense features (eg, inspecting imports) in JS files (not TS files) seem to work fine:

enter image description here

8
  • What do you mean with "highlight"? Do you maybe want to use typescript, or a linter?
    – ASDFGerte
    Mar 3, 2021 at 13:11
  • I think you need to install jshint marketplace.visualstudio.com/items?itemName=dbaeumer.jshint
    – Elvis
    Mar 3, 2021 at 13:13
  • 1
    Install the ESlint extension for your VS code.
    – m3hran
    Mar 3, 2021 at 13:13
  • @m3hran that fixed it. I wasn't sure what was intellisense and what was eslint. Want to add your comment to an answer and I'll mark it as accepted? Mar 3, 2021 at 13:17
  • Default javascript has no type checks, no safety nets, no nothing. That's good, when you need a very short script, maybe even in node repl, and just "want to get things done quick"/"do things". There, if you have some implicit global iDontExist, you don't need to first explicitly declare everywhere that "yeah that exists, stop complaining". For anything else, i'd always recommend typescript+linter.
    – ASDFGerte
    Mar 3, 2021 at 13:24

1 Answer 1

6

Undefined functions in VSCode aren't automatically highlighted when they are undefined because of globals, this includes a totally different setup to get the highlighting running:

Using the ESlint Extension to get undefined functions or errors highlighted.

enter image description here

You can also use ts-check, which is what I use and has been working fine.

1
  • 1
    Hi Ayo -- I just saw your talk at NVIDIA. I know this isn't the normal channel to get in touch. But thanks for your efforts for SO and the African developer community. Apr 15, 2021 at 12:12

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.