TypeScript Programming with Visual Studio Code has an issue of converting typescript file to JavaScript file

Welcome to our new article on “TypeScript Programming with Visual Studio Code having an issue of converting typescript file to JavaScript file”. In this article, I will explain how to solve the issue of converting the typescript file to JavaScript file when compiled the typescript file.

When we have compiled typescript file in visual studio code, it will be converted into a JavaScript file but it doesn’t convert. Basically, when compiled it, the typescript code converted to javascript code.

I have created a “Sample.ts” file in visual studio code. Next for creating a tsconfig.json file, type command as “tsc –init”.

typescript generate tsconfig.json file
typescript generate tsconfig.json file

I have compiled “Sample.ts” file using the command “tsc Sample.ts” or “tsc Sample”. Then it is generated a javascript file without code means it doesn’t convert typescript file to JavaScript file as shown below.

Type Script Programming with Visual Studio Code
Type Script Programming with Visual Studio Code

Because “sourceMap”: true, is missing in the tsconfig.json file. if you have observed in the first screen there is no – “sourceMap”:true in tsconfig.json file.

why we need SourceMap in “tsconfig.json” file, it will Generate corresponding ‘.map’ file. Now copy and paste – “sourceMap”: true, in “tsconfig.json” file.

typescript sourcemap tsconfig
typescript sourcemap tsconfig

Now we can compile the typescript file again then it will be converted into JavaScript file successfully.

typescript compile command
typescript compile command

For output use command “node Sample.ts” or “node Sample”.

convert typescript to javascript visual studio code
TypeScript Programming with Visual Studio Code

You may like following SPFx tutorials:

Here we discussed, how to solve the issue of converting typescript file to javascript file when compiled typescript in visual studio code.

>