0
votes

enter image description here

enter image description here

enter image description here

Argument of type '(book: Book) => void' is not assignable to parameter of type '(value: unknown) => void | PromiseLike'. Types of parameters 'book' and 'value' are incompatible. Type 'unknown' is not assignable to type 'Book'.

1
Apparently this.booksServices.getSingleBook (which you haven't shown) returns a Promise<unknown>, so there's no guarantee you'll get a Book back. Please give a minimal reproducible example as text.jonrsharpe
@jonrsharpe I just edited the question with code for booksServices.getSingleBooksarv19
As screenshots. Code is text, post it as such. But yes, that function lacks any information as to what it might return a promise of.jonrsharpe

1 Answers

-1
votes

There's a difference between any and unknown.

In short for your case - you can't treat unknown as anything, or as Book like you did in your code. If your method returned Promise<any> or Promise<Book> you'd be able to do what you attempted here.

I would go with the latter and annotate the getSingleBook method as such:

getSingleBook(id: number): Promise<Book> {
//...
const potentialBook = data.val();
const book: Book = validateBook(potentialBook); // throw an error if not a book
resolve(book);
//...
}

You can just assert the resolved value as a book if you're 100% sure it is and always will be, but that's ill advised:

getSingleBook(id: number): Promise<Book> {
//...
resolve(book as Book);
//...
}

Thanks jonrsharpe.