本文介绍了如何在 Visual Studio Code 中使用 app-module-path 进行 IDE 类型感知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在他们使用 app-module-path 的节点环境中,以便始终可以从基本路径写入需求.

I'm in a node environment where they are using app-module-path so that the requires can always be written from a base path.

所以所有路径都可以是:const something = require('/api/something') 而不必使用类似的东西来回退文件夹结构:const something = require('../../api/something).

So all path's can be: const something = require('/api/something') instead of having to back down the folder structure with something like: const something = require('../../api/something).

如果没有确切的路径,VSCode 会说所有类型都是 any 类型.这意味着转到定义"之类的功能将不起作用.

Without the exact path, VSCode says all types are of type any. This means functionality like 'go to definition' won't work.

有没有办法配置 VSCode 来解决这个问题?

Is there a way to configure VSCode to address this?

推荐答案

经过更多搜索,我发现这可以通过使用具有以下设置的 jsconfig.son 文件来完成.

After some more searching I found this can be done by using a jsconfig.son file with the following settings.

{
    "compilerOptions": {
        "target": "ES6",
        "allowSyntheticDefaultImports": true,
        "jsx": "react",
        "module": "commonjs",
        "baseUrl": ".",
        "paths": {
            "*": [
          "*",
          "app/*"
        ]
        }
    },
    "include": [
      "app/**/*.js"
    ]
}

这篇关于如何在 Visual Studio Code 中使用 app-module-path 进行 IDE 类型感知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 18:21