typescript

npx tsc --init is compulsory in typescript


I prefer installing Typescript locally in a project folder by running:

npm i typescript --save-dev

After installing the Typescript compiler, my tutorial told me to run npx tsc --init to initialize the typescript project and create the tsconfig.json file. However, when I don't run (npx tsc --init), my typescript code still transpiles normally.

Is npx tsc --init compulsory in initial typescript projects? My project is quite tiny. Its purpose is to show the results of the code when I try typescript syntax and concepts.

When manually setting up the reality TS project, is running npx tsc --init compulsory or are other things done to set up the project manually?

I used this article on Google to set up the project for learning TS.


Solution

    1. Running npx tsc --init is not strictly compulsory to transpile TypeScript code. The purpose of running npx tsc --init is to generate a tsconfig.json file, which allows you to configure the TypeScript compiler options for your project. If you don't have a tsconfig.json file, TypeScript still can use its default settings to compile your code. This is why your TypeScript code still transpiles normally even without running npx tsc --init.

    2. When setting up a TypeScript project manually, running npx tsc --init is a convenient way to generate a tsconfig.json file with default settings, but it is not the only way. You can manually create a tsconfig.json file as well.

    However, having a tsconfig.json file is highly recommended as your project grows, as it gives you more control over the compilation process and helps ensure consistency across different environments.