Having tsconfig.json will help you to manipulate your Typescript project easier. So how to generate a tsconfig.json file? This article will give you a simple method to do it. Let’s go into detail now.
Generate a tsconfig.json file
Let’s follow two steps to generate a tsconfig.json file.
Step 1: Download TypeScript
First, ensure your computer already has npm to help you manage and download the package. If not, download NodeJS here. You already have npm. Turn on your terminal at your project’s file and run these commands:
npm install typescript@latest -g
This command will help you download Typescript’s latest version with –g stands for global.
You can check with this command:
If the output is something like this:
That means you download success. If not, you should try this command:
Sudo npm install typescript@latest –g
This command will help you solve the error related to permissions.
npm install typescript@latest –g -force
This command will make npm re-download all packages you have and force you to download Typescript.
Step 2: Generate a tsconfig.json
You can generate a tsconfig.json file by this command:
You will get something like this notification.
You can turn on your file tsconfig.json by command:
You will find a tsconfig.json file with first look like this:
const aString: string = 'Hello From Learn Share IT.' const anArray : number = [0,1,2,3,4,5,6,7,8,9,10] console.log(aString) console.log(anArray)
Then I get this file:
var aString = 'Hello From Learn Share IT'; var anArray = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; console.log(aString); console.log(anArray);
Hello From Learn Share IT. [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
In this tutorial, we showed you how to generate a tsconfig.json file. You can download TypeScript and then use the tsc –init command to generate a tsconfig.json file. If you have any questions, please comment below. We will answer as possible. Thank you for your reading!
Maybe you are interested:
- How to run a TypeScript file from the Command line
- How to read a File’s contents in TypeScript
- How to write to a File using TypeScript
Name of the university: HOU