如何生成tsconfig。Json通过命令行? 我尝试命令tsc init,但这不起作用。


当前回答

我在用这个,

yarn add -D typescript
yarn tsc --init

这为我解决了问题

其他回答

对于那些已经将TypeScript安装为本地包(也可能是作为开发依赖项)的人来说:

$ npm install typescript --save-dev

...以及谁在package.json中添加了TSC脚本:

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

你可以通过npm调用tsc——init:

$ npm run tsc -- --init 

我在用这个,

yarn add -D typescript
yarn tsc --init

这为我解决了问题

运行TSC -- --init 这适用于下面的package.json

  "devDependencies": {
    "@types/jasmine": "^3.6.2",
    "@types/node": "^14.14.19",
    "jasmine": "^3.6.3",
    "protractor": "^7.0.0",
    "typescript": "^4.1.3"
  },

这招对我很管用:

tsc --init

从2实施。您可以在.zshrc或.bashrc中添加一个函数,以快捷方式到本地bin路径。

# in .zshrc:
function npm-do { (PATH=$(npm bin):$PATH; eval $@;) }

# working inside your directory:
npm-do tsc --init