Skip to content

Unable to pass another react component as prop with strictNullChecks #11944

Closed
@asvetliakov

Description

@asvetliakov

I'm not sure where to file issue - here or in DT repo, but i believe it's more TS issue rather than typings issue, since it's valid to return null in StatelessComponent definition

TypeScript Version: 2.0.6
@types/react": "^0.14.43"
strictNullChecks: true

Code

import * as React from "react";
interface Props {
   Component: React.ComponentClass<any> | React.StatelessComponent<any>
}

class MyComponent extends React.Component<Props, {}> {
   render() {
     const Component = this.props.Component;
     return <Component />;
  }
}

Expected behavior:
Compiles fine

Actual behavior:

'JSX element type 'ReactElement<any> | null' is not a constructor function for JSX elements.
  Type 'null' is not assignable to type 'ElementClass'.'

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions