I am having a TypeScript error:
Argument of type '(element: Conversation) => void' is not assignable to parameter of type '(value: Conversations, index: number, obj: Conversation[]) => boolean'. Type 'void' is not assignable to type 'boolean'.
This is my schema
export class Conversation {
constructor(
public id: number,
public dateTime: Date,
public image: string,
public isUnread: boolean,
public title: string
) {}
}
and this is my code
// Mark as read also in data store
this.dataStore.data.find((element) => {
if (element.id === conversationId) {
element.isUnread = true;
// Push the updated list of conversations into the observable stream
this.observer.next(this.dataStore.data);
}
});
What does this error means? Thank in you in advance.
This question is related to
typescript
Your code is passing a function as an argument to find
. That function takes an element
argument (of type Conversation
) and returns void
(meaning there is no return value). TypeScript describes this as (element: Conversation) => void'
What TypeScript is saying is that the find
function doesn't expect to receive a function that takes a Conversation and returns void. It expects a function that takes a Conversations
, a number
and a Conversation
array, and that this function should return a boolean
.
So bottom line is that you either need to change your code to pass in the values to find
correctly, or else you need to provide an overload to the definition of find
in your definition file that accepts a Conversation
and returns void
.
Source: Stackoverflow.com