Skip to content

Comment in JSX counted as a child when it shouldn't be #41125

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

Closed
aweary opened this issue Oct 15, 2020 · 0 comments · Fixed by #41166
Closed

Comment in JSX counted as a child when it shouldn't be #41125

aweary opened this issue Oct 15, 2020 · 0 comments · Fixed by #41166
Assignees
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.

Comments

@aweary
Copy link

aweary commented Oct 15, 2020

TypeScript Version: Nightly

Search Terms: React, JSX, Comment, React.ReactElement

Code

import * as React from 'react'

interface Props {
    children: React.ReactElement
}

function Wrapper(props: Props) {
    return <div>{props.children}</div>
}

const element = (
    <Wrapper>
    {/* comment */}
     <div>Hello</div>
    </Wrapper>
)

Expected behavior: The {/* comment */} should be ignored by the type checker as it is completely stripped away when the JSX is compiled

Actual behavior: The comment is considered a child of Wrapper and a type error is thrown as Wrapper expects a single React.ReactElement child

Playground Link: https://www.typescriptlang.org/play?ts=4.1.0-dev.20201015#code/JYWwDg9gTgLgBAKjgQwM5wEoFNkGN4BmUEIcA5FDvmQFA3AB2MWUBeWcACsWOgN404QuLgAWwADYATSgwBcmKjAB02PDACiErCCxMaAXzoEArg3zAIDOAHUoyMGBYAKMD1QLuEXgEo4A4ThKGBMoawAeKWAANwA+PjdvVGUxSRk9A3CAeii4wzpcK1R4LG1dJjgAXjhnQWFwuwcnKFi6oT4spEKQcvgELKNAuEiY2IAJUokIbNzWwOzGxxZWnyA

Related Issues: N/A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants