Tag Archives fortypescript

Line 0: Parsing error: : Cannot read property ‘map’ of undefined

the error displayed: Cannot read property 'map' of undefined

If you’re using React and typescript, try these few actions:

  1. Reinstall the dependencies: rm -rf node_modules; yarn install
  2. Remove the cache that’s inside the build directory: remove the build directory and restart the node service
  3. This did it for me (and Trat Westerholt) : don’t type your variables/constants as ‘bare’ arrays:

This failed:

// don't do this - a 'bare' array as type
const customers: [] = []

SOLUTION: It was fixed by:

// add a type to the array
const customers: string[] = []