typescript 如何生成 tsconfig.json 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36916989/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I generate a tsconfig.json file?
提问by Rajab Shakirov
How can I generate a tsconfig.json
via the command line?
I tried command tsc init
, but this doesn't work.
如何tsconfig.json
通过命令行生成一个?我试过 command tsc init
,但这不起作用。
回答by Remo H. Jansen
It is supportedsince the release of TypeScript 1.6.
自 TypeScript 1.6 发布以来就支持它。
The correct command is --init
not init
:
正确的命令--init
不是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:
如果版本早于 1.6,则需要更新:
$ npm install -g typescript
Remember that you need to install node.js to use npm.
请记住,您需要安装 node.js 才能使用 npm。
回答by Diego Santa Cruz Mendezú
this worked for me:
这对我有用:
tsc --init
回答by Bojan Komazec
For those who have TypeScript installed as a local package (and possibly as a dev dependency) via:
对于那些通过以下方式将 TypeScript 安装为本地包(也可能作为开发依赖项)的人:
$ npm install typescript --save-dev
...and who have added tscscript to package.json:
...以及谁已将tsc脚本添加到 package.json:
"scripts": {
...
"tsc": "tsc"
},
You can call tsc --init
via npm
:
您可以tsc --init
通过npm
以下方式致电:
$ npm run tsc -- --init
回答by Little Roys
Setup a ts project as following steps:
按照以下步骤设置 ts 项目:
- install typescript
yarn global add typescript
- create a package.json: run
yarn init
or setting defaultsyarn init -yp
- create a tsconfig.json: run
tsc --init
- (*optional) add tslint.json
- 安装打字稿
yarn global add typescript
- 创建package.json:运行
yarn init
或设置默认值yarn init -yp
- 创建一个tsconfig.json:运行
tsc --init
- (*可选) 添加tslint.json
The project structure seems like:
项目结构看起来像:
│ package.json
│ tsconfig.json
│ tslint.json
│ yarn.lock
│
├─dist
│ index.js
│
└─src
index.ts
回答by Sloka Roy
I recommend to uninstall typescript first with the command:
我建议先使用以下命令卸载打字稿:
npm uninstall -g typescript
then use the chocolateypackage in order to run:
然后使用巧克力包来运行:
choco install typescript
in PowerShell.
在 PowerShell 中。
回答by AissaDevLab
install TypeScript :
安装打字稿:
npm install typescript
add tsc script to package.json:
将 tsc 脚本添加到 package.json:
"scripts": {
"tsc": "tsc"
},
run this:
运行这个:
npx tsc --init