共计 684 个字符,预计需要花费 2 分钟才能阅读完成。
在 vue3+ts 的项目中,遇到 ts 报错,代码如下:
import { reactive, toRefs, onBeforeMount, onMounted, ExtractPropTypes } from 'vue'
interface Item {
width?: string | number;
label?: string;
prop?: string;
}
type columnsType = ArrayItem>;
const props = defineProps({
data: {
type: Array,
default: []
},
columns: {
type: Array,
default: []
}
})
const data = props.data as any;
const columns = props.columns as unknown as columnsType;
报错如图:
安装的插件为 Volar,其实这里错误提示的翻译有误,英文本意为导出的东西使用了 Item,但这个接口没导出。
将 Item 那个 interface 导出即可:
export interface Item {
width?: string | number;
label?: string;
prop?: string;
}
另一种方式为,不使用 interface, 直接使用 type 也不会报错,代码如下:
type Item = {
width?: string | number;
label?: string;
prop?: string;
}
2022/11/14 更新
最新排查出现此问题的原因,使用了 slot, 并添加了参数传递。
原文地址: vue3 ts 报错:模块的默认导出具有或正在使用专用名称“Item”。ts(4082)
正文完