如何强制VSCode使用本地安装的TypeScript [英] How to force VSCode to use locally installed TypeScript

查看:67
本文介绍了如何强制VSCode使用本地安装的TypeScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编辑该项目时,是否有办法强制Visual Studio Code使用本地安装在JS项目中的TypeScript(而不是与VSCode捆绑在一起的版本或全局安装的版本)进行类型检查?

Is there a way to force Visual Studio Code to use the TypeScript installed locally in a JS project (instead of the version bundled with VSCode, or the version installed globally) for type checking when editing that project?

推荐答案

我假设您已经在 myProject 目录中安装了TypeScript.

I assume that you have installed TypeScript in the myProject directory.

cd myProject
npm install --save-dev typescript

如果已经这样做,则添加一个 .vscode/目录和一个 settings.json 文件,该文件指定要使用的TypeScript SDK:

If you have already done that, then add a .vscode/ directory with a settings.json file that specifies the TypeScript SDK to use:

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

这是最终的目录结构:

myProject
  .vscode
    settings.json
  node_modules
    typescript
      lib

重要提示:请确保您在 myProject 目录中打开VSCode!

Important: make sure that you open VSCode in the myProject directory!

VS Code文档将其称为"使用TypeScript的工作区版本."

The VS Code documentation calls this "using the workspace version of TypeScript."

这篇关于如何强制VSCode使用本地安装的TypeScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆