0

I'm trying to combine two arrays into one using the spread object like below:

const queryVariable = {
      ...this.state,
      filters: [...Object.keys(extraFilters || {}), ...this.state.filters],
    }

this.state.filters is an array here. But typescript gives me the following error:

Type must have a '[Symbol.iterator]()' method that returns an iterator.

What am I doing wrong here?

2 Answers 2

4

Check the typescript compilier options in tsconfig.json

 "compilerOptions": {
    "target": "es6"
 }

Refer this https://github.com/Microsoft/TypeScript/issues/22768

Sign up to request clarification or add additional context in comments.

Comments

0

It is complaining (probably) about the ...this.state. Spread operator on objects is an ES2018 functionality.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.