0

I am sending an array of data to a component as a prop, like:

<InfoTable TableInfo={tableRows} />;

Where tableRows is the array.

On my InfoTable component file I define my props like

interface InfoTableProps {
  tableInfo: TableInfo[];
}

Which allows me to .map() through the tableInfo array, eg:

let tableRow = tableInfo.map(function(tableInfoRow) {
  // Do some stuff
}

This works fine. However, my compiler gets a warning on tableInfo: TableInfo[];

Cannot find name 'TableInfo'. TS2304

I've tried Googling the problem of course but I just get people asking the same question.

Would anyone know how to remove this error or what it means?

1
  • 1
    And it looks like you've named the prop as tableInfo but you're passing TableInfo={}, so maybe it's just a typo? Commented May 27, 2020 at 2:00

1 Answer 1

1

Don't you need to define the TableInfo type somewhere?

eg

Interface TableInfo {
  id: number
  name: string
}

Sorry If you've already done that and its something else :-)

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

3 Comments

So I need to declare each key in the array as well?
yes. rn typescript doesn't know the structure of each item in your array. When you write TableInfo[], you're saying "an array of TableInfo-shaped things". Typescript wants to know what each of those things looks like.
that'll be due to the typo that Emile mentioned above :)

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.