3

I cannot get Visual Studio Code to update the version of typescript it is running.

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:

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

This will call tsc with the -v command (to output the version).

When I press ctrl+shift+B the output reads

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?

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

NOTE II: I have tried restarting Visual Studio Code several times.

NOTE III: When I run tsc -v from a command prompt from C: it outputs 2.1.4

I am running Visual Studio Code 1.8.1

Update:

I changed my tasks.json to run where tsc and this was the output:

running command> where 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

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...

1 Answer 1

3

I work on TypeScript and JavaScript support in VSCode.

The typescript.tsdk sets the version of TypeScript used inside VSCode for IntelliSense. It does not impact which version of tsc used for running the tasks. The tasks use the same logic as the command line to resolve tsc.

To use your local copy of tsc in the task, change the task.json to:

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

or, on 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.

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you very much for the answer! I had tried something similar and could not get it to work. When I put in what you suggested I got an error. Adding in isShellCommand as true gave me the error message: '.' is not recognized as an internal or external command, operable program or batch file. I tried to take out the leading '.' (and some other combinations) but I could not get it to work.
Since you are windows, you have to use a windows style path: .\\node_modules\\.bin\\tsc.cmd. I've updated the answer to show this as well.
That was it! Thank you very much!
I am using VSCode and I no longer have the ability to switch Typescript version. I don't see the current version in the bottom right toolbar, and I don't see a menu for Typescript version either. I have lost all intellisense. Tried to downgrade to 1.3 version of VSCode but see the exact same behaviour. I tried to google which leads me down the path of setting typescript.tsdk but to no avail! @MattBierner do you have any ideas why this may be so?
It sounds like the built-in JavaScript and TypeScript language features extension is disabled. In the extensions view, search @builtin to make sure it is enabled

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.