Visual Studio Code 使用什么 TypeScript 版本?如何更新? [英] What TypeScript version is Visual Studio Code using? How to update it?

查看:155
本文介绍了Visual Studio Code 使用什么 TypeScript 版本?如何更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何判断 Visual Studio Code 中使用的 TypeScript 版本?特别是,我一直在使用 TypeScript 1.8.10 和 VSCode 1.4.0.我首先将 VSCode 更新到最新版本,即 1.5.3.但是从命令行检查,我看到我的 TypeScript 版本仍然是 1.8.10.所以我从命令行更新了 TypeScript,现在是 2.0.3.

有没有办法确定 Visual Studio Code 是否使用 2.0.3 版?

是否有更新 Visual Studio Code 的方法可以自动将 TypeScript 更新到最新发布的版本,还是必须独立完成 TypeScript 更新?

解决方案

TypeScript 可以自动更新吗?

<块引用>

VS Code 附带了最新的稳定版 TypeScript.

– 来自

<小时>

更改全局 TypeScript 版本

  1. 全局安装所需的 TypeScript 版本,例如 npm install -g typescript@2.0.5
  2. 打开 VS Code 用户设置 (F1 > 打开用户设置)
  3. 更新/插入 "typescript.tsdk": "{your_global_npm_path}/typescript/lib" 你可以通过输入 npm root -g 找到 {your_global_npm_path}

现在你用 VS Code 打开的所有项目都将使用这个 TypeScript 版本,当然除非有一个工作区设置覆盖它.

<小时>

更改本地 TypeScript 版本

  1. 在 VS Code 中打开项目
  2. 在本地安装所需的 TypeScript 版本,例如 npm install --save-dev typescript@2.0.5

    --save-dev 将更新您项目的 package.json,将您安装的 TypeScript 版本添加为 devDependency.

  3. 打开 VS Code 工作区设置 (F1 > 打开工作区设置)

  4. 更新/插入 "typescript.tsdk": "./node_modules/typescript/lib"

    现在只有你安装了这个 TypeScript 版本的项目才会使用那个 TypeScript 版本,全局安装会被这个项目中的 VS Code 忽略.

  5. 添加了 typescript.tsdk 条目后,还需要使用 VS Code UI 来选择新版本:

    • 点击 VS Code 页脚中显示的版本:

    • 在用户界面中选择它:

<小时>

另见:

How can I tell what version of TypeScript is being used in Visual Studio Code? In particular, I had been using TypeScript 1.8.10 and VSCode 1.4.0. I first updated VSCode to the latest version, which was 1.5.3. But checking from the command line, I saw that my TypeScript version was still 1.8.10. So I updated TypeScript from the command line, and it is now 2.0.3 .

Is there a way to tell for sure whether Visual Studio Code is using version 2.0.3?

Is there a method for updating Visual Studio Code that will automatically update TypeScript to the latest released version, or does the TypeScript update have to be done independently?

解决方案

Can TypeScript be updated automatically?

VS Code ships with a recent stable version of TypeScript.

– from VS Code docs

This means there's no way to automatically upgrade the TypeScript version used by VS Code. You can however override the TypeScript version VS Code uses by modifying either the user settings or the workspace settings.


What TypeScript version is VS Code using?

When you open a TypeScript file, VS Code should display the TypeScript version in the status bar at the bottom right of the screen:


Changing the global TypeScript version

  1. Install the desired TypeScript version globally, for example npm install -g typescript@2.0.5
  2. Open VS Code User Settings (F1 > Open User Settings)
  3. Update/Insert "typescript.tsdk": "{your_global_npm_path}/typescript/lib" you can find out {your_global_npm_path} by typing npm root -g

Now all of the projects you open with VS Code will use this TypeScript version, unless of course there is a workspace setting that overrides this.


Changing the local TypeScript version

  1. Open the project in VS Code
  2. Install the desired TypeScript version locally, for example npm install --save-dev typescript@2.0.5

    The --save-dev will update your project's package.json, adding the TypeScript version you installed as a devDependency.

  3. Open VS Code Workspace Settings (F1 > Open Workspace Settings)

  4. Update/Insert "typescript.tsdk": "./node_modules/typescript/lib"

    Now only the project you installed this TypeScript version in will use that TypeScript version, the global installation will be ignored by VS Code in this project.

  5. Having added the typescript.tsdk entry it's then also necessary to use the VS Code UI to select the new version:

    • Click on the version displayed in the VS Code footer:

    • Select it in the UI:


See also:

这篇关于Visual Studio Code 使用什么 TypeScript 版本?如何更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆