Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I generate a tsconfig.json file?

Tags:

typescript

People also ask

What is Tsconfig json file?

The tsconfig. json file specifies the root files and the compiler options required to compile the project. JavaScript projects can use a jsconfig. json file instead, which acts almost the same but has some JavaScript-related compiler flags enabled by default.

Can you have multiple Tsconfig json files?

You could use multiple tsconfig files to solve some of those problems, but new ones would appear: There's no built-in up-to-date checking, so you end up always running tsc twice. Invoking tsc twice incurs more startup time overhead. tsc -w can't run on multiple config files at once.


It is supported since the release of TypeScript 1.6.

The correct command is --init not init:

$ tsc --init

Try to run in your console the following to check the version:

$ tsc -v

If the version is older than 1.6 you will need to update:

$ npm install -g typescript

Remember that you need to install node.js to use npm.


For those who have TypeScript installed as a local package (and possibly as a dev dependency) via:

$ npm install typescript --save-dev

...and who have added tsc script to package.json:

"scripts": {
   ...
   "tsc": "tsc"
},

You can call tsc --init via npm:

$ npm run tsc -- --init 

If you don't want to install Typescript globally (which makes sense to me, so you don't need to update it constantly), you can use npx:

npx -p typescript tsc --init

The key point is using the -p flag to inform npx that the tsc binary belongs to the typescript package


this worked for me:

tsc --init

You need to have typescript library installed and then you can use

npx tsc --init 

If the response is error TS5023: Unknown compiler option 'init'. that means the library is not installed

yarn add --dev typescript

or for npm

npm i --save-dev typescript

and run npx command again

I recommend not to install dependencies globally as it is easier to manage the versioning for each project. It is also easier for coworkers to see an install what is needed to run the project with one command.


Setup a ts project as following steps:

  • install typescript yarn global add typescript
  • create a package.json: run yarn init or setting defaults yarn init -yp
  • create a tsconfig.json: run tsc --init
  • (*optional) add tslint.json

The project structure seems like:

│  package.json
│  tsconfig.json
│  tslint.json
│  yarn.lock
│
├─dist
│      index.js
│
└─src
       index.ts