简体   繁体   English

Visual Studio代码忽略打字稿版本设置

[英]Visual Studio Code ignores typescript version settings

I cannot get Visual Studio Code to update the version of typescript it is running. 我无法让Visual Studio Code更新它正在运行的打字稿版本。

I have read the answer to this question in detail. 我已经详细阅读了这个问题的答案。

I have tried setting my user settings to: 我尝试将用户设置设置为:

{
    "typescript.tsdk": "C:\\Users\\myUser\\AppData\\Roaming\\npm\\node_modules\\typescript\\lib"
}

This did not help. 这没有用。

I have also tried setting my workspace setting to: 我也尝试将我的工作区设置为:

{
    "typescript.tsdk": "./node_modules/typescript/lib"
}

This also seemed to have no effect. 这似乎也没有效果。

I configured my task runner to run tasks.json and have it set to the following: 我配置我的任务运行器来运行tasks.json并将其设置为以下内容:

{
    "version": "0.1.0",
    "command": "tsc",
    "args": ["-v"],
    "echoCommand": true
}

This will call tsc with the -v command (to output the version). 这将使用-v命令调用tsc(以输出版本)。

When I press ctrl+shift+B the output reads 当我按ctrl + shift + B时​​输出读取

running command> tsc -v 运行命令> tsc -v
Version 1.8.34 版本1.8.34

Is there something else I need to do to get Visual Studio Code to update its version of Typescript? 我还需要做些什么来让Visual Studio Code更新其Typescript版本吗?

NOTE: I went to both of the paths I tried above and did a tsc -v in the bin folder and both returned 2.1.4 注意:我去了上面尝试的两个路径,并在bin文件夹中执行了tsc -v ,并且都返回了2.1.4

NOTE II: I have tried restarting Visual Studio Code several times. 注意二:我已经尝试多次重启Visual Studio Code。

NOTE III: When I run tsc -v from a command prompt from C: it outputs 2.1.4 注3:当我从C:命令提示符运行tsc -v时 ,它输出2.1.4

I am running Visual Studio Code 1.8.1 我正在运行Visual Studio Code 1.8.1

Update: 更新:

I changed my tasks.json to run where tsc and this was the output: 我改变了我的tasks.json来运行tsc ,这是输出:

running command> where tsc 运行命令>其中tsc
C:\\Program Files (x86)\\Microsoft SDKs\\TypeScript\\1.8\\tsc.exe C:\\ Program Files(x86)\\ Microsoft SDKs \\ TypeScript \\ 1.8 \\ tsc.exe
C:\\Program Files (x86)\\Microsoft SDKs\\TypeScript\\1.8\\tsc.js C:\\ Program Files(x86)\\ Microsoft SDKs \\ TypeScript \\ 1.8 \\ tsc.js
C:\\Users\\myUser\\AppData\\Roaming\\npm\\tsc C:\\ Users \\用户MYUSER \\应用程序数据\\漫游\\故宫\\ TSC
C:\\Users\\myUser\\AppData\\Roaming\\npm\\tsc.cmd C:\\用户\\ MYUSER \\应用程序数据\\漫游\\故宫\\ tsc.cmd

So I can see where it is getting the older version of typescript from, but I don't understand WHY it is not using the "overridden" version. 所以我可以看到它从哪里获得旧版本的打字稿,但我不明白为什么它没有使用“重写”版本。

My only guess is that the override is not for building. 我唯一的猜测是覆盖不是用于构建。 It is only for intelisense and such. 它只适用于知识分子等。 Still, I need a way to change this... 不过,我需要一种方法来改变这个......

I work on TypeScript and JavaScript support in VSCode. 我在VSCode中处理TypeScript和JavaScript支持。

The typescript.tsdk sets the version of TypeScript used inside VSCode for IntelliSense. typescript.tsdk设置内部VSCode用于智能感知的打字稿的版本。 It does not impact which version of tsc used for running the tasks. 它不会影响用于运行任务的tsc版本。 The tasks use the same logic as the command line to resolve tsc . 任务使用与命令行相同的逻辑来解析tsc

To use your local copy of tsc in the task, change the task.json to: 要在任务中使用tsc的本地副本,请将task.json更改为:

{
    "version": "0.1.0",
    "command": "./node_modules/.bin/tsc",
    "args": ["-v"],
    "echoCommand": true
}

or, on windows: 或者,在Windows上:

{
    "version": "0.1.0",
    "command": ".\\node_modules\\.bin\\tsc.cmd",
    "args": ["-v"],
    "echoCommand": true
}

Hope that helps clear things up. 希望有助于澄清事情。 Please let us know if have any ideas for making the documentation of this more clear, or you can even submit a PR to improve the docs . 如果您有任何关于使文档更清晰的想法,请告知我们 ,或者您甚至可以提交PR来改进文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM