5

是显示问题的 Github MCVE。npm run compile显示错误。

我正在尝试这样做:

import {Todo} from '@test';

但这并没有解决。

src/index.ts:1:20 - 错误 TS2307:找不到模块“@test”。

pathstsconfig.json.

  "baseUrl": "./",                          /* Base directory to resolve non-absolute module names. */
  "paths": {
    "@fs/": ["src/"], 
    "@test/": ["test/"]
  },                                        /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */

想法?

Github 打字稿问题

我在这里打开了一个错误报告,因为根据一些评论它应该有效。

Typescript 请注意,我更新了 github 存储库,删除了@test.

4

2 回答 2

5

不要调整 VS Code Import Module Specifier 设置(根据一些浮动的答案)。并且不要删除 glob 模式。实际上添加更多:

 "baseUrl": "./",
  "paths": {
    "@fs/*": ["src/*"], 
    "@test/*": ["test/*"]
  },

请注意,glob 位于键和值中。有时很难发现这一点。

如果目标是文件,则应从键和值中省略 glob。

于 2019-11-09T19:06:34.487 回答
2

删除 glob 模式:

"paths": {
  "@test": "./test"
}

您的解决方案应该可以正常工作,但是文档没有使用 glob,并且在使用 glob 时报告了一些智能感知错误

于 2019-03-27T18:18:58.247 回答