在vue3+ts的项目中, 遇到ts报错,代码如下:
import { reactive, toRefs, onBeforeMount, onMounted, ExtractPropTypes } from 'vue'
interface Item {
width?: string | number;
label?: string;
prop?: string;
}
type columnsType = Array<Item>;
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+TypeScript的项目开发中,遇到类型报错,主要涉及接口Item未导出及slot参数传递导致的问题。解决方案包括导出接口Item或使用type定义Item,从而消除ts报错。此外,更新提到问题可能由slot的使用和参数传递引起。
1120

被折叠的 条评论
为什么被折叠?



