typescript debug

128 阅读1分钟

安装依赖时报错

error An unexpected error occurred: "EPERM: operation not permitted, unlink

在装包的时候,由于文件被占用导致无法删除文件,因此就会报错,只需要关闭相应的占用程序即可。


$ yarn build

打包时报错

Top-level await is not available in the configured target environment ("es2015")

「ECMAScript」提案 Top-level await 由 Myles Borins 提出,可以让你在模块的最高层中使用 await 操作符。在这之前,你只能通过在 async 函数或 async generators 中使用 await 操作符。

Top-level await 是个新特性,打包不支持此特性。


TS2345: Argument of type '{ cookId: string; }' is not assignable to parameter of type 'DashFoodPageDto'.   Object literal may only specify known properties, and 'cookId' does not exist in type 'PageDto<DashFoodDto, any>'.

当对象字面量中的属性在对象类型中不存在时,会发生“Object literal may only specify known properties”错误。 要解决该错误,请确保键入对象的所有属性并修复属性名称中的拼写错误(如果有)。


const typeOptions = ref([])

TS2322: Type '{ label: string | undefined; value: string | undefined; }[]' is not assignable to type 'never[]'.   Type '{ label: string | undefined; value: string | undefined; }' is not assignable to type 'never'.

错误:类型“xxx”不能分配给类型“never[]”

原因:如果ts中声明变量时没有声明类型,默认的话会是never[],而其他类型不能分配给类型never[],

解决:在声明变量时声明类型

const typeOptions = ref([] as Array<OptionVo>)