Reputation: 387
I'm trying to execute this computed method:
get dronesFiltered(){
const filtered = this.drones.filter((drone) => {
return drone.id.toString().indexOf(this.filterId) > -1 && drone.name.toLowerCase().toString().indexOf(this.filterName.toLowerCase()) > -1 && drone.status.toLowerCase().toString().indexOf(this.selectedStatus.toLowerCase()) > -1 && this.statusFly(drone.fly, drone.status).indexOf(this.selectedCurrentFly) > -1;
});
return filtered;
}
It runs ok, but show this errors:
Property 'status' does not exist on type 'never'
It happens to status,id,name,fly (every field that i'm trying to do a filter). How can I handle it?
Here's my component code:
@Component({})
export default class List extends Vue {
drones = []
selectedStatus = ''
selectedCurrentFly = ''
filterId = ''
filterName = ''
mounted(){
this.listDrones(1);
}
get dronesFiltered(){
const filtered = this.drones.filter((drone) => {
return drone.id.toString().indexOf(this.filterId) > -1 && drone.name.toLowerCase().toString().indexOf(this.filterName.toLowerCase()) > -1 && drone.status.toLowerCase().toString().indexOf(this.selectedStatus.toLowerCase()) > -1 && this.statusFly(drone.fly, drone.status).indexOf(this.selectedCurrentFly) > -1;
});
return filtered;
}
public async listDrones(current: number) {
try {
const res = await dronesController.getDronesWithLimit(current);
const resTotal = await dronesController.getDrones();
this.totalRows = resTotal.data.length;
this.drones = res.data;
} catch (err) {
console.log(err);
}
}
}
Upvotes: 3
Views: 10995
Reputation: 3573
Just to provide clarification ;)
Since we expect --strictNullChecks to almost always be used in combination with --noImplicitAny, it seems pointless to widen the type of empty array literals from never[] to any[] since we'll immediately report an implicit any error following the widening. It seems better to preserve the more specific never[] type and require the programmer to add a type annotation if the array is actually going to be modified.
as explained here: TypeScript GitHub pull #8944
Upvotes: 3
Reputation: 387
I solved my problem, i just had to add this to my 'drones' variable (but I did not understand why i had to do it):
drones: any[] = []
Upvotes: 1