How have IDE type awareness with app-module-path in Visual Studio Code

泄露秘密 提交于 2021-01-27 07:11:44

问题


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.

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).

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

Is there a way to configure VSCode to address this?


回答1:


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"
    ]
}


来源:https://stackoverflow.com/questions/47082341/how-have-ide-type-awareness-with-app-module-path-in-visual-studio-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!