为什么 VS Code 建议我通过相对路径而不是我在 tsconfig.json 中定义的路径别名自动导入?

Coe*_*oel 6 intellisense typescript tsconfig visual-studio-code

我的项目结构是这样的:

---- apps
---- libs
-------- index.ts
-------- commmon
-------- service
------------ index.ts
------------ src
---------------- index.ts
---------------- goods
-------------------- index.ts
-------------------- src
------------------------ index.ts
------------------------ goods.service.ts
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

每个index.ts都有一个 export * from '...' 语句。

我的tsconfig.json在下面:

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false,
    "paths": {
      "@frosticx/library": [
        "libs"
      ]
    }
  }
}

Run Code Online (Sandbox Code Playgroud)

我希望从库导入的所有内容都应该是import { ... } from '@frosticx/library';,但是 Vistual Studio 不会重新调整此路径别名: 在此输入图像描述

手动指定@frosticx/library可以,但是正如您所看到的,Visual Studio 不会将其视为模块: 在此输入图像描述

sta*_*all 7

尝试"typescript.preferences.importModuleSpecifier": "non-relative"settings.json 文件中进行设置。该设置的默认值是"shortest",这可能是这里的问题,因为您的别名似乎比可以导入模块的相对路径长。

注意:谷歌搜索建议:github typescript issues auto import use tsconfig paths.