Skip to content

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

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
gaspard opened this issue Jun 7, 2017 · 2 comments

Comments

@gaspard
Copy link

gaspard commented Jun 7, 2017

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

@gaspard
Copy link
Author

gaspard commented Jun 7, 2017

Some other references:

DefinitelyTyped/DefinitelyTyped#14284

#11566

@gaspard
Copy link
Author

gaspard commented Jun 7, 2017

Sorry for the trouble. This has been fixed. Using typescript 2.3.4 works (but I have to figure out what version of tsc DefinitelyTyped is using in CI).

@gaspard gaspard closed this as completed Jun 7, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant