-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
JSX Stateless Functional Components Property 'children' is missing in type. #7992
Comments
Duplicate of #6471? |
I'm not 100% sure if it is the same or not. I can reproduce the same behaviour with a fully expanded component definition class Test extends React.Component<{children: any}, {}>{
render() {
return <span>{this.props.children}</span>
}
}
<Test>123</Test>; Will, fail with the same error. And the work-around of changing the type definition to: {children?: any} works, but is pretty undesirable. The workaround I have for stateless components is that I can write it: const Test = (props: {children?:any}) => <span>{props.children}</span>; which again isn't ideal. Another work-around is const Test = ({children=null}) => <span>{children}</span>; or, more explicitly, const Test = ({children} : {children?: any}) => <span>{children}</span>; This is probably the best that can be had without special case code for handling children. |
@bennoleslie I realize that it isn't a duplicate. I think you just want to make const Test = ({ children = undefined }) => <span>{children}</span> |
I realize this might be a non-issue, but I can't seem to find any good example anywhere of how to use stateless components with children - I'm assuming it's possible somehow? main.tsx
at compile-time, this error is emitted in the console:
I'm trying to compile with
|
@opvasger what about sth like this: const Wrapper: React.StatelessComponent<{ children?: React.ReactNode}> = ({ children }) =>
<div>{children}</div> |
@fakiolinho hehe, yea - I've done it like this since:
I didn't realize it at the time, but children are implicitly passed, which I guess makes sense 😄 |
Should be addressed by #13618 |
TypeScript Version:
1.8.9 / (1.9.0-dev.20160409)
Code
Expected behavior:
No errors.
Actual behavior:
If I change the JSX to:
there is no error reported.
The text was updated successfully, but these errors were encountered: