In my Angular app I have a filter function that keeps track of both user inputed filter values, and whether or not those filter values are currently enabled/active. I am initializing these filters like so:
filters = { language: [], location: [], zipArray: [], firstName: [], lastName: [] };
I am running into a Typescript error with this section of code -- specifically this line: return this.filters.zipArray = [];
public onZipcodeEnabledChange(enabled): void {
this.filters.zipArray = this.getZipcodeArray();
if (!enabled || this.filters.zipArray && this.filters.zipArray[0] === ''){
return this.filters.zipArray = [];
}
}
The TypeScript error I'm getting is:
Type 'undefined[]' is not assignable to type 'void'.
I'm not understanding what the issue is here?
onZipcodeEnabledChangeasvoid, but you're returning an empty array. Try writingreturn;on its own line after you set thezipArrayfilters.