首页 文章

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

提问于
浏览
3

我无法让Visual Studio Code更新它正在运行的打字稿版本 .

我已经详细阅读了this question的答案 .

我尝试将用户设置设置为:

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

这没有用 .

我也尝试将我的工作区设置为:

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

这似乎也没有效果 .

我配置我的任务运行器来运行tasks.json并将其设置为以下内容:

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

这将使用-v命令调用tsc(以输出版本) .

当我按ctrl shift B时输出读数

running command> tsc -v Version 1.8.34

Is there something else I need to do to get Visual Studio Code to update its version of Typescript?

注意:我去了上面尝试的两个路径,并在bin文件夹中执行了tsc -v,并且都返回了2.1.4

注意二:我已经尝试多次重启Visual Studio Code .

注3:当我从C:命令提示符运行tsc -v时,它输出2.1.4

我正在运行Visual Studio Code 1.8.1

更新:

我改变了我的tasks.json来运行tsc,这是输出:

running command>其中tsc C:\ Program Files(x86)\ Microsoft SDKs \ TypeScript \ 1.8 \ tsc.exe C:\ Program Files(x86)\ Microsoft SDKs \ TypeScript \ 1.8 \ tsc.js C:\ Users \ myUser \ AppData \ Roaming \ npm \ tsc C:\ Users \ myUser \ AppData \ Roaming \ npm \ tsc.cmd

所以我可以看到它从哪里获得旧版本的打字稿,但我不明白为什么它没有使用“重写”版本 .

我唯一的猜测是覆盖不是用于构建 . 它只适用于知识分子等 . Still, I need a way to change this...

1 回答

  • 3

    我在VSCode中处理TypeScript和JavaScript支持 .

    typescript.tsdk 设置用于IntelliSense的VSCode内部使用的TypeScript版本 . 它不会影响用于运行任务的 tsc 版本 . 任务使用与命令行相同的逻辑来解析 tsc .

    要在任务中使用 tsc 的本地副本,请将 task.json 更改为:

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

    或者,在Windows上:

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

    希望有助于澄清事情 . 请let us know如果有任何想法使这个文件更清楚,或者你甚至可以submit a PR to improve the docs .

相关问题