typescript - 如何使用自定义类型绑定导入相关组件
问题描述
所以我有一个像这样设置的项目文件路径:
app
- src
- views
- mypage.vue
- tsconfig.json
common
- types
- test.d.ts
- test.js
但是,当我尝试像下面这样(在 mypage.vue 中)导入我的 test.js 文件时,根据我实现导入的方式,我收到以下错误。
尝试1:
进口:
import * as test from '../../../common/test'
测试.d.ts
declare module 'test' { ... }
结果:
cannot find declaration file for ../../../common/test
尝试2:
进口:
import * as test from '../../../common/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'
测试.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
解决方案
推荐阅读
- javascript - Hapi.js 17.xx:如何从处理函数返回响应而不返回
- ubuntu - blk_update_request:I/O 错误,dev sda,扇区 xxxxxxxxxxx
- javascript - 在 IIFE 上使用 .call(this)
- raspberry-pi - 如何使用 Android Things 获得 LV-MaxSonar LV-EZ0 测距仪的每个规格输出?
- elasticsearch - kibana 如何创建一个仪表板来汇总一些日志记录的列
- json - Codeigniter 3.1.8 JSON 发布失败
- matlab - 如何将 PCA 应用于 HOG 特征的 FFT?
- javascript - 无法根据要求读取以下数据(在 java 脚本中)
- javascript - 如何将点击事件处理程序添加到单个 img 元素?
- c - 如何在函数内初始化 Struct 指针数组?