TypeScript error: Type 'void' is not assigned to type 'boolean'

I have a TypeScript error:

An argument of type '(element: Conversation) => void' is not assigned to a parameter of type '(value: Conversations, index: number, obj: Conversation []) => boolean'. The type 'void' is not assigned to the type 'boolean'.

This is my scheme.

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 mean? Thank you in advance.

+4
source share
2 answers

This means that the callback function passed to this.dataStore.data.findmust return a boolean and have 3 parameters, two of which may be optional:

  • Meaning: Conversations
  • index: number
  • obj: Conversation []

( void). :

this.dataStore.data.find((element, index, obj) => {
    // ...

    return true; // or false
});

this.dataStore.data.find(element => {
    // ...

    return true; // or false
});

, : , find, . , , find , .

, data, data, true, , find.

+10

find. element ( Conversation) void ( , ). TypeScript (element: Conversation) => void'

TypeScript, , find , void. , Conversations, a number Conversation, boolean.

, , find, find , Conversation void.

+3

All Articles