typescript - 您可以为根目录之外的引用设置路径别名吗
问题描述
我正在开发一个具有以下目录结构的打字稿项目
├── common
│ ├── tsconfig.json
│ ├── Schemas
│ └── Types
├── server
│ ├── tsconfig.json
│ ├── src
│ └── test
└── viewer
├── tsconfig.json
├── src
└── tests
我已经以tsconfig.json
这种方式成功设置了对服务器和查看器中公共目录的引用
"references": [
{ "path": "../common" }
]
所以我可以包含公共文件
import EventListSchema from '../../../../common/Schemas/EventList';
但是,我想像我一样设置一个路径别名src
"paths": {
"@/*": [ "src/*" ],
"common/*": [ "../common/*" ] // something like this
},
所以我可以包含具有更简单路径的常见文件,例如
import EventListSchema from 'common/Schemas/EventList';
当我尝试添加时common
出现paths
此错误
error TS2307: Cannot find module 'common/Schemas/EventList' or its corresponding type declarations.
import EventListSchema from 'common/Schemas/EventList';
这样的事情可能吗?我正在使用tsc
版本 4.0.2
解决方案
推荐阅读
- spring - Spring 如何将查询参数反序列化为 Kotlin 数据类?
- java - 来自 Path 的 Java SSLHandshakeException 不与任何信任锚链接
- python - 将列表中的所有元素打印到矩形中的函数
- python-3.x - 如何让 discord bot 自动发送直接消息 [Discord.py]
- java - Java 适合网站形式。编译问题
- bash - 如何将 .tab.gz 文件合并为一个不重复列标题的 gz 文件?
- firebase - Flutter:从A类的TextField中获取值并将其传递给另一个B类
- docker - 如何在 docker-compose 中挂载单个文件
- php - 由于权限,无法将文件上传到服务器
- azure-aks - dapr 自托管应用程序可以调用托管在 kubernetes 上的远程 dapr 服务吗?