How to enable typescript check in javascript file [ Javascript type checking without typescript]

In this post, I will show you how to enable typescript type checking in in JavaScript file.`

Let’s suppose you have the following file code in javascript.

var a=10;
console.blog('Hello World');

You can see the second line is console.blog which is not a valid function also you can see there is no error shown in the editor.

If you want typescript to check your file for error(s), you can enable it by simply  adding the following line at the top of your file

//@ts-check

once you add the above line in your file, you will immediately see the error that blog is a not function on console. See the below image for the error message.

Reactions

Post a Comment

0 Comments

Close Menu