如何安装 TypeScript?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23267858/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 01:14:49  来源:igfitidea点击:

How do I install TypeScript?

installtypescript

提问by David Thielen

I have version 0.9.1.1. So I ran the following:

我有 0.9.1.1 版本。所以我运行了以下内容:

C:\test>npm install -g typescript
npm http GET https://registry.npmjs.org/typescript
npm http 200 https://registry.npmjs.org/typescript
npm http GET https://registry.npmjs.org/typescript/-/typescript-1.0.0.tgz
npm http 200 https://registry.npmjs.org/typescript/-/typescript-1.0.0.tgz
C:\Users\david\AppData\Roaming\npm\tsc -> C:\Users\david\AppData\Roaming\npm\nod
e_modules\typescript\bin\tsc
[email protected] C:\Users\david\AppData\Roaming\npm\node_modules\typescript

But when I run tsc I get:

但是当我运行 tsc 时,我得到:

C:\test>tsc
Version 0.9.1.1
Syntax:   tsc [options] [file ..]

What else do I need to do to install the latest version?

我还需要做什么来安装最新版本?

Update:

更新:

C:\test>where tsc
C:\Program Files (x86)\Microsoft SDKs\TypeScript\tsc.exe
C:\Program Files (x86)\Microsoft SDKs\TypeScript\tsc.js
C:\Users\david\AppData\Roaming\npm\tsc
C:\Users\david\AppData\Roaming\npm\tsc.cmd

tsc.exe is 0.9.1.1 and tsc.cmd is 1.0.0.0

tsc.exe 是 0.9.1.1 和 tsc.cmd 是 1.0.0.0

I then removed the VisualStudio 0.9.1.1 AddIn and it's now all good - just tsc.cmd and that's 1.0.0.0

然后我删除了 VisualStudio 0.9.1.1 AddIn,现在一切都很好 - 只是 tsc.cmd 就是 1.0.0.0

Thank you all!

谢谢你们!

采纳答案by basarat

What else do I need to do to install the latest version?

我还需要做什么来安装最新版本?

It is because you probably (almost definitely) have TypeScript plugin for visual studio installed. You can uninstall that from Control Panel. Then the typescript you installed from npmwill be the default one on the command line.

这是因为您可能(几乎肯定)安装了 Visual Studio 的 TypeScript 插件。您可以从控制面板卸载它。然后,您从npm安装的打字稿将成为命令行上的默认打字稿。

Alternatively you can get the latest TypeScript from Visual Studio 2012 plugin from here : http://www.typescriptlang.org/#Download(For VS 2013 it is bundled as a part of VS 2013 update 2 RC)

或者,您可以从这里获取来自 Visual Studio 2012 插件的最新 TypeScript:http: //www.typescriptlang.org/#Download(对于 VS 2013,它作为 VS 2013 update 2 RC 的一部分捆绑在一起)

回答by amin

Removing C:\Program Files (x86)\Microsoft SDKs\TypeScript\from PATHenvironment variable did the job for me.

C:\Program Files (x86)\Microsoft SDKs\TypeScript\PATH环境变量中删除为我完成了这项工作。

Advanced system settings -> Environment Variables -> system variables -> PATH

Advanced system settings -> Environment Variables -> system variables -> PATH

回答by John Peters

TypeScript Version Issues and How to Update using NPM

TypeScript 版本问题以及如何使用 NPM 进行更新

I had a similar issue, whereby I downloaded both 1.4 and the beta version of 1.5, when I ran the command tsc -v, it kept returning version 1.0...

我有一个类似的问题,我下载了 1.4 和 1.5 的测试版,当我运行命令 tsc -v 时,它一直返回 1.0 版......

When I went to the folder indicated above, I saw three versions 1.0, 1.4. and 1.5. deleting 1.0 allowed 1.5 to run...

当我进入上面指示的文件夹时,我看到了 1.0、1.4 三个版本。和 1.5。删除 1.0 允许 1.5 运行...

enter image description here

在此处输入图片说明

回答by quiary

For me, I just change the "Path" environment parameter from "C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0"to "C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.5", then it's all ok.

对我来说,我只是将“Path”环境参数从"C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0"更改为"C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.5",然后就可以了。

回答by Neil Busse

Before you do this make sure you have typed in

在执行此操作之前,请确保您已输入

npm install -g typescript

I went to

我去了

C:\Program Files (x86)\Microsoft SDKs\TypeScript\

C:\Program Files (x86)\Microsoft SDKs\TypeScript\

And deleted the 1.0 folder After doing that I did tsc -v on the command line and it finally returned 2.7 as shown below.

并删除了 1.0 文件夹之后,我在命令行上执行了 tsc -v 并最终返回了 2.7,如下所示。

PS c:\users\username> tsc -v
Version 2.7.2

回答by Sheo Dayal Singh

How Do I install TypeScript?

如何安装 TypeScript?

First we have to install the node.js. Download it from this location

首先,我们必须安装 node.js。从这个位置下载

https://nodejs.org/en/download/

https://nodejs.org/en/download/

and run the .msi installer, to check whether it is installed or not just use below command in command prompt

并运行 .msi 安装程序,以检查它是否已安装,只需在命令提示符下使用以下命令

node -v

节点 -v

It would display the version of the installed node.js.

它将显示已安装 node.js 的版本。

Then use below command in command prompt to install the TypeScript

然后在命令提示符下使用以下命令安装 TypeScript

npm install -g typescript

npm install -g 打字稿

回答by Shiva

You installed it correctly but while calling the compiler you just need to mention the path of the source file,something like this:

您正确安装了它,但是在调用编译器时您只需要提及源文件的路径,如下所示:

C:\test>tsc example.ts

Check this linkfor more information

检查此链接以获取更多信息