Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tutorial w/TypeScript] Warning: 'ArticlesCell' return type 'Element[]' not a valid JSX element. #5008

Closed
Philzen opened this issue Apr 3, 2022 · 5 comments · Fixed by #5020
Assignees
Labels
topic/typescript tutorial-qa Redwood Tutorial QA Week related items

Comments

@Philzen
Copy link
Contributor

Philzen commented Apr 3, 2022

Working through the tutorial in TypeScript mode, VSCode complains about the ArticlesCell return type:

grafik

Interestingly, the warning doesn't appear while the Success function still returns the Articles wrapped in <ul>, it only starts appearing when we change them to render as individual <article>s as advised at the end of https://redwoodjs.com/docs/tutorial/chapter2/cells#our-first-cell

However, wrapping <ArticlesCell /> in a fragment or a div in Homepage.tsx does not make the warning go away.

Compilation succeeds nevertheless so it's possible to continue the tutorial, but still it would be nice to know which type to annotate the cell with so this warning goes away.

Reporting this non-critical finding here as advised.

@jtoar jtoar moved this to Needs triage in Triage Apr 3, 2022
@jtoar jtoar added this to Triage Apr 3, 2022
@Philzen
Copy link
Contributor Author

Philzen commented Apr 3, 2022

Suggestion: enhance the tutorial code snippets with a TypeScript tab so that first-timers can also learn about the correct types while working through it.

@Philzen
Copy link
Contributor Author

Philzen commented Apr 3, 2022

@simoncrypta I've created a repository that follows each of the steps for your convenience, you can checkout / reset to Philzen/redwoodblog-tutorial-typescript@2acdd84 and play that through yourself.

@simoncrypta simoncrypta added topic/typescript tutorial-qa Redwood Tutorial QA Week related items labels Apr 3, 2022
@simoncrypta
Copy link
Collaborator

Typescript see success as an array of element (but I think it should be an array of component, but I don't know if this really change something) which is not, like the error say, a valid JSX component. I wrap the map function inside a React fragment to fix this. Maybe we should have done this way in the tutorial, but I let @cannikin decide what he thinks about that.

// web/src/components/ArticlesCell/ArticlesCell.tsx

[...]

export const Success = ({ articles }: CellSuccessProps<ArticlesQuery>) => {
  return (
    <>
      {articles.map((article) => (
        <Article key={article.id} article={article} />
      ))}
    </>
  )
}

@simoncrypta
Copy link
Collaborator

Also, the error will be fixed later in the tutorial

export const Success = ({ articles }) => {
  return (
    <div className="space-y-10">
      {articles.map((article) => (
        <Article article={article} key={article.id} />
      ))}
    </div>
  )
}

@Philzen
Copy link
Contributor Author

Philzen commented Apr 4, 2022

I wrap the map function inside a React fragment to fix this. Maybe we should have done this way in the tutorial, but I let @cannikin decide what he thinks about that.

// web/src/components/ArticlesCell/ArticlesCell.tsx
export const Success = ({ articles }: CellSuccessProps<ArticlesQuery>) => {
  return (
    <>
      {articles.map((article) => (
        <Article key={article.id} article={article} />
      ))}
    </>
  )
}

Thanks, of course that is the obvious solution and makes the error go away 👍 ... why didn't i think of that – i did actually try React fragment around <ArticlesCell /> but of course that's the same difference 🤦 😆

IMHO it should be done that way for the time being in chapter 2 so RedwoodJS learners are left with valid code until they get to chapter 5. I took the liberty to prepare #5020 for this.

Philzen added a commit to Philzen/redwood that referenced this issue Apr 4, 2022
This avoids warning `'ArticlesCell' cannot be used as a JSX component.
Its return type 'Element[]' is not a valid JSX element.`.

Closes redwoodjs#5008
Philzen added a commit to Philzen/redwood that referenced this issue Apr 4, 2022
This avoids warning `'ArticlesCell' cannot be used as a JSX component.
Its return type 'Element[]' is not a valid JSX element.`.

Closes redwoodjs#5008
Philzen added a commit to Philzen/redwood that referenced this issue Apr 4, 2022
This avoids warning `'ArticlesCell' cannot be used as a JSX component.
Its return type 'Element[]' is not a valid JSX element.`.

Closes redwoodjs#5008
cannikin pushed a commit that referenced this issue Apr 5, 2022
This avoids warning `'ArticlesCell' cannot be used as a JSX component.
Its return type 'Element[]' is not a valid JSX element.`.

Closes #5008
Repository owner moved this from Needs triage to Done in Triage Apr 5, 2022
@cannikin cannikin moved this to Done in Tutorial QA Week Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic/typescript tutorial-qa Redwood Tutorial QA Week related items
Projects
Status: Done
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants