所以我的项目文件路径设置如下:
app
- src
- views
- mypage.vue
- tsconfig.json
common
- types
- test.d.ts
- test.js
但是,当我尝试导入如下所示的test.js文件时(在mypage.vue中),基于实现导入的方式,会出现以下错误。
尝试1:
导入:
import * as test from '../../../common/test'
test.d.ts
declare module 'test' { ... }
结果:
cannot find declaration file for ../../../common/test
尝试2:
导入:
import * as test from '../../../common/test'
test.d.ts
declare module '../../../common/test' { ... }
结果:
module declaration cannot specify relative module name
尝试3:
tsconfig.json
"paths": {
"@common/*": [
"../common/*"
]
}
导入:
import * as test from '@common/test'
test.d.ts
declare module '@common/test' { ... }
结果:
Failed to compile with 1 error
This dependency was not found:
@common/test
To install it, you can run: npm install --save @common/test