Type hints for JavaScript in Visual Studio Code

Type hints for JavaScript in Visual Studio Code

You've got some javascript you want to refactor so you open Visual Studio Code and get cracking. But since you've decided to write it in plain javascript it's an untyped mess. You look at that property you just renamed, are you sure you found all instances of it? Are you sure if you just decided to Find-and-Replace that you haven't accidentally renamed something else?

If only you could make VS Code treat your javascript like typescript, just for a moment...

Simply put this at the very beginning of the file and that's exactly what VS Code will do

// @ts-check

This will probably give you a lot of false positives, global variables such as jQuery will be marked as errors as it can't find a definition but better to have to sort through some false positives and be sure that you are changing what you think you are.

Share Tweet Send
You've successfully subscribed to SimonReynolds.ie
Great! Next, complete checkout for full access to SimonReynolds.ie
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.