0

So im trying to populate an Array to then pass a prop to another Component.

const arrayList = (): ArrayList[] => {
let remaining: number = 0
let stateArrayList: String[] = []
for (let i = 0; remaining > i; i++) {
    stateArrayList.push("Blah")
}
return (arrayList)

Results in the following error

Type '() => String[]' is missing the following properties from type 'String[]': pop, push, concat, join, and 27 more.  TS2322

I have looked around online using the TS2322 issue code, but cant seem to find a resolution.

Any help would be appreciated

2
  • 1
    What's an ArrayList? Commented Dec 11, 2019 at 22:36
  • 1
    Please consider editing the code to constitute a minimal reproducible example as described by the guidelines for How to Ask. As it stands it references undefined types like ArrayList and seems to be incomplete (there's at least a missing closing brace). It does seem like the main problem is likely to be that you're returning the function itself instead of stateArrayList. Commented Dec 12, 2019 at 0:51

1 Answer 1

1

You're returning arrayList (the function) but I think you wanted actually to return stateArrayList (the array).

Like this :

const arrayList = (): ArrayList[] => {
  let remaining: number = 0
  let stateArrayList: String[] = []
  for (let i = 0; remaining > i; i++) {
      stateArrayList.push("Blah")
  }
  return stateArrayList
}
Sign up to request clarification or add additional context in comments.

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.