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

React's 'children' property is not properly recognized #6471

Closed
pdeva opened this issue Jan 13, 2016 · 3 comments
Closed

React's 'children' property is not properly recognized #6471

pdeva opened this issue Jan 13, 2016 · 3 comments
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead Domain: JSX/TSX Relates to the JSX parser and emitter

Comments

@pdeva
Copy link

pdeva commented Jan 13, 2016

say I have:

class Parent extends React.Component<{children:any}, {}>{
  render() {
     return <div> {this.props.children}</div>
  }
}

class Container extends React.Component<{},{}> {

    render() {
        return <Parent> //typescript shows error here cause no 'children' attribute present
         <h2>Hello</Hello>
        </Parent>
    }
}

In this case, Container is calling Parent correctly by passing in the children as nested elements.
However, Typescript still complains that it doesnt see an explicit 'children' attribute.

Typescript should know that 'children' attribute is special.

TS version 1.7.3

@RyanCavanaugh RyanCavanaugh added the By Design Deprecated - use "Working as Intended" or "Design Limitation" instead label Jan 13, 2016
@RyanCavanaugh
Copy link
Member

We've decided not to special-case the children attribute because it's so React-specific.

The recommended practice is to write the props type as {children?: any}

@simonbuchan
Copy link

Seems like strange reasoning if you have complierOptions.jsx set to react, looking for a namespace React, with handling of react intrinsic properties like ref and key, to be worried about being react specific any more :)

Perhaps JSX.ContentAttributesProperty with @types/react declaring { children: ReactNode }?

@mhegazy
Copy link
Contributor

mhegazy commented Mar 28, 2017

#13618 should address this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead Domain: JSX/TSX Relates to the JSX parser and emitter
Projects
None yet
Development

No branches or pull requests

5 participants