7

I'm an error that Type 'Function' provides no match for the signature for the filter below. Which is true because filter expects a specific type. How would define my callback to match what filter expects?

private _getItemFilteredBy(itemName: string, Fn: Function): Observable<any[]> {
    return this.getItemByName(itemName)
        .map((items: any[]) => {
            return items.filter( Fn );
        });
}

1 Answer 1

9

Filter needs a predicate. Change the type to (x:any) => boolean

private _getItemFilteredBy(itemName: string, Fn: (x:any) => boolean): Observable<any[]> {
    return this.getItemByName(itemName)
        .map((items: any[]) => {
            return items.filter( Fn );
        });
}

If you have more specific type information than 'any', I'd recommend updating that too but what I've posted above should work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.