vue3使用Vite打包是Ts检查报错问题

问题一

error TS6133: ‘calendarSwitch’ is declared but its value is never read.

描述:

calendarSwitch被声明,但它的值永远不会被读取,
该参数或该方法你定义好了,但是却没有用到,无法通过Ts检查,所以报错

解决:

注释掉该方法或该参数,使用哪些参数就定义哪些参数,不要多定义,多定义不使用就会报错。

问题二

error TS: Cannot find module ‘element-plus/es/locale/index.js’ or its corresponding type declarations.

import { it } from “element-plus/es/locale/index.js”;

描述:

找不到模块’element-plus/es/locale/index.js’或其相应的类型声明
可能是声明的地址不对,在vs code中使用Ctrl键+鼠标左键,点击在"element-plus/es/locale/index.js
上,看能不能进入该文件地址里,如果进不去,就是地址不对。不过也有可能是element-plus框架自己的问题

解决:

书写正确的地址,或在node_modules/vite-plugin-mock/dist/index.mjs文件里加入如下代码:

    import { createRequire } from 'module';
    const require = createRequire(import.meta.url);

问题三

error TS2345: Argument of type ‘{ title: string; left: string; normal: { name: string; value: number; }; standard: { name: string; value: number; }; }’ is not assignable to parameter of type ‘never’.

basicList.push(basicJson);

描述

类型“{ title: string; left: string; normal: { name: string; value: number; }; standard: { name: string; value: number; }; }”的参数不能赋给类型“never”的参数
这是因为我把一个对象添加到空数组中,没有给数组定义类型所导致的。

解决:

给basicList定义any类型,或者其他适合的类型

暂时就遇到这些问题,如遇到其他问题再进行补充。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐