I have a compile error I do not understand.
If I have an EntityState And store Persons in the store then trying to see if a specific id does exist, I tried follwoing code:
this.store.select(fromPersonSelectors.selectPersonIds)
.pipe(tap(theIds => console.log("pipe-tab theIds"+typeof theIds)))
.pipe(filter(theIds => {
if (theIds !== null && isNumberArray(theIds)) {
theIds.find((oneId:number) => oneId.toFixed(0) === this.personId)
// !==this.personId
}
}), take(1))
...
export function isNumberArray(array: string[] | number[]): array is number[] {
return typeof array[0] === 'number';
}
selectPersonIds is returning from the entity library, from '@ngrx/entity', which is used by the store:
export interface EntitySelectors<T, V> {
selectIds: (state: V) => string[] | number[];
V is the PersonDTO
A compile error I do not understand comes with the second .pipe (.pipe(filter(theIds => {) stating:
TS2769: No overload matches this call. Overload 1 of 5, '(predicate: (value: string[] | number[], index: number) => value is string[] | number[]): OperatorFunction<string[] | number[], string[] | number[]>', gave the following error. Argument of type '(theIds: string[] | number[]) => void' is not assignable to parameter of type '(value: string[] | number[], index: number) => value is string[] | number[]'. Signature '(theIds: string[] | number[]): void' must be a type predicate. Overload 2 of 5, '(predicate: BooleanConstructor): OperatorFunction<string[] | number[], string[] | number[]>', gave the following error. Argument of type '(theIds: string[] | number[]) => void' is not assignable to parameter of type 'BooleanConstructor'. Types of parameters 'theIds' and 'value' are incompatible. Type 'T' is not assignable to type 'string[] | number[]'. Type 'T' is not assignable to type 'number[]'. Overload 3 of 5, '(predicate: (value: string[] | number[], index: number) => boolean): MonoTypeOperatorFunction<string[] | number[]>', gave the following error. Argument of type '(theIds: string[] | number[]) => void' is not assignable to parameter of type '(value: string[] | number[], index: number) => boolean'. Type 'void' is not assignable to type 'boolean'
Perhaps someone knows, tnx in advance.
filter
needs to return a boolean.
The code that is shared doesn't return something within filter
, and is thus a void. That's why you get the error Type 'void' is not assignable to type 'boolean'
.