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.

JavaScript type checking without typescript

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 not function on console. See the below image for the error message.

JavaScript type checking without typescript

إرسال تعليق

Please do not post any spam link in the comment box😊

أحدث أقدم

Blog ads

CodeGuru