Check out a free preview of the full Visual Studio Code course:
The "Type Checking in VS Code" Lesson is part of the full, Visual Studio Code course featured in this preview video. Here's what you'd learn in this lesson:

Mike demonstrates how to activate in VS Code.

Get Unlimited Access Now

Transcript from the "Type Checking in VS Code" Lesson

>> Mike: We can activate type checking in Visual Studio Code in one of two ways. If you're working with a project that already involves typescript, you would go to this tsconfig file, which is in the root of your project, and you would add this to your configuration. Say checkJs : true, that means it's not just gonna look at the typescript files and make sure the types are good there, it'll also check your regular JavaScript.

[00:00:25] Additionally, regardless of what kind of JavaScript program you're working with, you can add this comment as the first line of the file and type checking will be done on that particular file. So if I go to, I'll need to create a new file here cuz I blew that one away.

[00:00:45] Collapse all.
>> Mike: Okay, so if I have something like this, let
>> Mike: Let x = 15.
>> Mike: So here I am messing with the types. No complaints, but when I add this, you can see we get type of 157 is not assignable to type number. So it's basically said okay, you initialized this.

[00:01:18] If I hover over x it's gonna say that's a number. And you better keep it a number because we don't flip flop around types anymore. Particularly, people make some mistakes in this area where they flip-flop between types, often when they're reading from an input or something. So if you've got an input and you expect a number to be there, you're basically gonna usually get text out of an input.

[00:01:46] So if you start out with initially my value is 15, and let's two-way bind this to the value of this input, it'll end up being a number, I mean, being a string as soon as the user hits a keystroke, usually. So that is how to use type checking in regular JavaScript, ts-check.