12

Requirement: When opening TypeScript files in VSCode, use the typescript version from node_modules instead of VSCode's TypeScript version

In .vscode/settings.json, I added the following settings as defined in the documentation:

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

However, VSCode still uses it's typescript version by default. I've reproduced the issue in vscode-typescript-default-version repository.

What needs to be done to use typescript version from node_modules by default when opening TypeScript files in VSCode?

Trivikram

2 Answers 2

9

When you have opened a typescript file, click on typescript version on the right bottom corner of vscode, and select Use Workspace Version.

enter image description here

If you need this configuration as default to all typescript files on vscode put the configuration on "User Settings" (ctrl+,).

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

In my case I have this file in ~/.config/Code/User. If you open a file on a directory whithout node_modules/typesript/lib a warning is shown:

The path /home/jahuuar/test/node_modules/typescript/lib doesn't point to a valid tsserver install. Falling back to bundled TypeScript version.

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

5 Comments

Thanks @jahuuar for the answer, but the question is what needs to be done that VSCode picks typescript version from node_modules by default
I understand. See my edited answer and remember to config in User Settings, not in Workspace Settings.
Thanks @jahuuatr , even if it's possible in User Settings the developer has to explicitly set it. I'm wondering if it's possible to override Typescript version in workspace settings by default.
I plan to create an issue with Github if that isn't possible github.com/Microsoft/vscode, I opened a question on StackOverflow as that's what VSCode issue template had recommended
@Trivikram probably User Settings will work only with a globally installed Typescript (local paths are just ignored in this case). If you want to use a local version - workspace settings are for that
3

I ran into an issue with VSCode showing a lot of typescript errors even though typescript was compiling my code just fine. The problem was that VSCode updated their typescript SDK to version 5 while my project was only meant to be using typescript 4.

To answer your question on whether you can force VSCode to use the workspace typescript by default: You can't.

Someone requested this feature in the VSCode github repo and it was rejected. I am using VSCode 1.77.1 and this feature still has not been implemented.

The only "solution" is to use the workaround described in this stackoverflow answer:

The best you can currently do is:

"typescript.tsdk": "./node_modules/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true,

Comments

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.