Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If I use a typescript tuple in my react-app i get a eslint error on line 1 in vscode?

The error is Parsing error: Cannot read property 'map' of undefined

I set up a new file just to reproduce the error:

export default () => {
  let something: [string, boolean]
  something = ['something', true];
}

am i missing something? all other types seem to work fine.

like image 503
spamspark Avatar asked Oct 18 '25 15:10

spamspark


1 Answers

The Problem

The problem is when you created the tuple type [string, boolean] this is a new way to declare types with arrays introduced in Typescript 4.0 called Labeled Tuple Types.

The Solution

Upgrade your react-scripts to v4 (Here is the issue on their github). If you are using yarn use the command yarn upgrade [email protected]. With npm should be something similar, you can try npm install [email protected]

like image 152
guitartsword Avatar answered Oct 21 '25 06:10

guitartsword