ketan
ketan

Reputation: 19341

Property map is missing in String Flowtype

Flowtype for array shows error.

type Props = {
  movies?: Array<any>
}

render() {
    const { movies } = this.props;

    return (
    <React.Fragment>
       <main className="moviedata-container"> {
          movies.map(movie => <MovieItem key={movie.id} movieItem={movie} />)
         }
        </main>
    </React.Fragment>
);
}

Error:

Cannot call movies.map because property map is missing in String [1]

Upvotes: 1

Views: 852

Answers (1)

debel27
debel27

Reputation: 421

Your type annotation indicates that the movies props could be undefined. You have to check that before being able to call .map().

Yet, I see no reason why the error is talking about String...

The reproduced example here works just fine.

Upvotes: 2

Related Questions