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


当前回答

我在用这个,

yarn add -D typescript
yarn 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

安装TypeScript:

npm install typescript

在package.json中添加TSC脚本:

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

运行这个:

npx tsc --init

自TypeScript 1.6发布以来就支持它。

正确的命令是——init而不是init:

$ tsc --init

尝试在控制台中运行以下命令来检查版本:

$ tsc -v

如果版本高于1.6,则需要更新:

$ npm install -g typescript

记住,你需要安装node.js才能使用npm。

我在用这个,

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