How can I generate a tsconfig.json file?

后端 未结 9 423
失恋的感觉
失恋的感觉 2020-12-04 10:48

How can I generate a tsconfig.json via the command line? I tried command tsc init, but this doesn\'t work.

相关标签:
9条回答
  • 2020-12-04 10:57

    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 
    
    0 讨论(0)
  • 2020-12-04 10:58

    install TypeScript :

    npm install typescript
    

    add tsc script to package.json:

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

    run this:

    npx tsc --init
    
    0 讨论(0)
  • 2020-12-04 11:00

    i am using this,

    yarn tsc --init
    

    this fixed it for me

    0 讨论(0)
  • 2020-12-04 11:06

    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
    

    and run npx command again

    0 讨论(0)
  • 2020-12-04 11:08

    this worked for me:

    tsc --init
    
    0 讨论(0)
  • 2020-12-04 11:11

    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

    0 讨论(0)
提交回复
热议问题