To see the last version: Go to: C:\Program Files (x86)\Microsoft SDKs\TypeScript, there you see directories of type 0.9, 1.0 1.1. Enter the high number that you have (in this case 1.1) Copy the directory and run in CMD the command tsc -v, you get the version.
Just open the IDE terminal and type in tsc -v and version will be displayed.
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.
When you open a TypeScript file, VS Code should display the TypeScript version in the status bar at the bottom right of the screen:
npm install -g [email protected]
Open User Settings
)"typescript.tsdk": "{your_global_npm_path}/typescript/lib"
you can find out {your_global_npm_path} by typing npm root -gNow 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.
Install the desired TypeScript version locally, for example npm install --save-dev [email protected]
The --save-dev
will update your project's package.json
, adding the TypeScript version you installed as a devDependency
.
Open VS Code Workspace Settings (F1 > Open Workspace Settings
)
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.
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:
typescript.tsdk
to make workspace usage clearerVisual Studio Code comes with its own stable version of TypeScript but you can switch to a newer version as described in their docs
VS Code ships with a recent stable version of TypeScript. If you want to use a newer version of TypeScript, you can define the typescript.tsdk setting (File > Preferences > User/Workspace Settings) pointing to a directory containing the TypeScript tsserver.js file.
...
For example:{ "typescript.tsdk": "node_modules/typescript/lib" }
Is there a way to tell for sure whether Visual Studio Code is using version 2.0.3?
Open up a TypeScript file in Visual Studio Code and in the bottom right you will see the version of TypeScript it's using:
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?
The way I've been doing it is to explicitly tell Visual Studio Code the folder where your TypeScript npm module is installed. I'm on Windows, so after you run the npm command to install TypeScript (npm install -g typescript
) it will install it in this folder:
C:\Users\username\AppData\Roaming\npm\node_modules\typescript\
So you need to tell Visual Studio Code to use the lib
folder of your TypeScript npm install. You do this by:
Open VS Code settings (File -> Preferences -> Settings)
Search for typescript.tsdk
setting
Find where npm installed TypeScript with: npm list -g typescript
. In my case, it returned C:\Users\username\AppData\Roaming\npm
Override the value of typescript.tsdk
setting to: C:\\Users\\username\\AppData\\Roaming\\npm\\node_modules\\typescript\\lib
Note the use of double backward slashes to have a properly escaped string with backward slashes.
Confirm that VS Code is using the npm version of TypeScript for intellisense by opening a TypeScript file, clicking the TypeScript version number in the bottom right and seeing in the task window that VS Code is loading TypeScript from the directory specified in step 4:
C:\Users\username\AppData\Roaming\npm\tsc.cmd (to something like tsc1.cmd)
Now try building in VS Code (Tasks -> Run Tasks -> tsc:build - tsconfig.json) and you should get this error message in the VS Code terminal window:
'tsc' is not recognized as an internal or external command, operable program or batch file.
The terminal process terminated with exit code: 1
To automatically use the Typescript version installed in your workspace's node_modules
, without having to configure it every time you set up a new workspace, you can set the default Typescript setting in the User Settings JSON (not Workspace) to use a relative path:
{
// ... other User settings
"typescript.tsdk": "./node_modules/typescript/lib"
}
Now, when you run the "Select Typescript Version..." command, the "VS Code's Version" will always be the same as the "Workspace Version":
The only potential downside to this is that it means you always need Typescript installed in the workspace you're working in. Though, if you're writing Typescript anywhere, I think that's a reasonable expectation.
You should see a version number listed on the bottom bar:
If you click on the number (2.4.0 above) you will be presented with an option to choose the version you would like to use:
If you don't see the version you want that means it probably isn't installed and you have to install it.
npm install -g [email protected]
Replace 2.7.2
with the version you want to install.
Though I could not find the file tsserver.js when I used Spotlight on my Mac, I tried again using mdfind, and I found its location to be "/usr/local/lib/node_modules/typescript/lib/"
So I used that path when editing my Workspace settings in settings.json
Now I am using my most recent version of TypeScript, and VSCode tells me that I am using my most recent version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With