0

I am getting the following error:

Argument of type '(item: ItemType) => void' is not assignable too parameter.

I can't seem to understand what's going on.

type MainProps = {
  book: Array<Object>;
  setFirstAction: (found: Array<Object>) => Array<Object>;
}
            
type ItemType = {
  volumeInfo: Object;
}
            
class Main extends Component<MainProps, {}> {
  render() {
    const { book } = this.props
    const books = book?.map((item: ItemType) => {
      //right here
      console.log(item.volumeInfo);
    })
    // console.log(book)

    return (
      <div className="wrapper">

      </div>
    )
  }
}
Emile Bergeron
  • 17,074
  • 5
  • 83
  • 129
Lex
  • 137
  • 1
  • 10
  • is it because the `map` function expects a return value? – Hozeis Aug 16 '21 at 18:03
  • TL;DR: `book: Array;` as `Object` do not have a `volumeInfo` property. – Emile Bergeron Aug 16 '21 at 18:04
  • I can't define item in map method. it works if I change it to item: any, but i want to item:Array and it doesn't work. It has to be typed – Lex Aug 16 '21 at 18:18
  • @dinis when you type `book: Array`, it tells typescript that the items are `Object`. Then, `ItemType` can't be used to type the items when looping since it's incompatible with the `Object` type. – Emile Bergeron Aug 16 '21 at 18:26

0 Answers0