Skip to content

TypeScript compile error: JSX element type 'ReactElement<any> | null' is not a constructor function for JSX elements. #16321

Closed
@gaspard

Description

@gaspard

TypeScript Version: 2.3.2

Code

// strictNullCheck: true
namespace React {
  interface StatelessComponent<P> {
    (props: P & { children?: ReactNode }, context?: any): ReactElement<any> | null;
    propTypes?: ValidationMap<P>;
    contextTypes?: ValidationMap<any>;
    defaultProps?: Partial<P>;
    displayName?: string;
  }
}
// All this is valid JSX
const Foo: React.StatelessComponent<any> = () => null
const bar = <Foo/>

Expected behavior:

JSX compilation should allow proper types (including null return).

Actual behavior:

Setting the proper return type for stateless components in @types/react yields a lot of failing other types as seen in this build fail: DefinitelyTyped/DefinitelyTyped#17021

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions