vue3 ts报错:模块的默认导出具有或正在使用专用名称“Item”。ts(4082)

11,348次阅读
没有评论

共计 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;

报错如图:
vue3 ts 报错:模块的默认导出具有或正在使用专用名称“Item”。ts(4082)
安装的插件为 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)

    正文完
     0
    Yojack
    版权声明:本篇文章由 Yojack 于2024-10-07发表,共计684字。
    转载说明:
    1 本网站名称:优杰开发笔记
    2 本站永久网址:https://yojack.cn
    3 本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行删除处理。
    4 本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
    5 本站所有内容均可转载及分享, 但请注明出处
    6 我们始终尊重原创作者的版权,所有文章在发布时,均尽可能注明出处与作者。
    7 站长邮箱:laylwenl@gmail.com
    评论(没有评论)