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


当前回答

安装TypeScript:

npm install typescript

在package.json中添加TSC脚本:

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

运行这个:

npx tsc --init

其他回答

你需要有typescript库安装,然后你可以使用

npx tsc --init 

如果响应是错误TS5023:未知编译器选项'init'。这意味着没有安装库

yarn add --dev typescript

或者是NPM

npm i --save-dev typescript

重新执行NPX命令

我建议不要全局安装依赖项,因为管理每个项目的版本更容易。对于同事来说,使用一个命令就可以更容易地看到运行项目所需的安装。

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

$ npm install typescript --save-dev

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

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

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

$ npm run tsc -- --init 

按以下步骤安装ts项目:

安装typescript yarn global 创建一个包。Json:运行yarn init或设置默认值yarn init -yp 创建一个tsconfig。Json: TSC——init (*可选)添加tslint.json

项目结构如下:

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

以防有人来这里找我要找的东西,tsconfig。Json文件,有更多选项

npx tsconfig.json 

对我不起作用,所以

npx tsconfig.json.cmd

给了我tsconfig。json文件,我正在寻找提供更多的选项

这在Windows上很管用

运行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"
  },