首页 > 解决方案 > VS Code 路径自动完成到操作系统的根目录

问题描述

我在 Visual Studio Code 中的 ts 项目显示了这条路径:~/以及它对 macos 根目录的建议,如屏幕截图所示。

发生了什么事?

在此处输入图像描述

我的 tsconfig:

{
  "compilerOptions": {
    "target": "esnext",
    "module": "commonjs",
    "strict": true,
    "jsx": "react",
    "rootDir": "./",
    "baseUrl": "./src",
    "paths": {
      "~*": ["./*"]
    },
    "incremental": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "lib": ["dom", "es2015", "webworker"]
  }
}

标签: visual-studio-code

解决方案


好的,找到了。

在 tsconfig 中应该是:

"paths": {
  "~/*": ["./*"]
},

代替

"paths": {
  "~*": ["./*"]
},

推荐阅读