经常用对象字面量的形式定义数据,如果遇到key是数组的话,很容易报错
Argument of type ‘string’ is not assignable to parameter of type ‘never’.
通常解决方式是用类型断言 as 来解决
// app列表
app = {
loading: false,
total: 1,
visible: false,
title: '',
name: [] as Array<string>
};
this.app.name.push('123')
这样就不报错了
工作上的总结,希望能帮助到你。