Skip to content

Possible regression with JSX and 2.3.1: Type '{}' is not assignable to type 'void' #15409

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
tkrotoff opened this issue Apr 27, 2017 · 2 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@tkrotoff
Copy link

tkrotoff commented Apr 27, 2017

With TypeScript 2.3.1 and 2.4.0-dev.20170427:

import * as React from 'react';
import * as ReactDOM from 'react-dom';

const FooBar1 = () => (
  <div></div>
);

                       // ===>
const FooBar2: React.SFC<void> = () => (
  <div></div>
);

const FooBar3: React.SFC<{}> = () => (
  <div></div>
);

ReactDOM.render(
  <div>
    <FooBar1 />
    
    // ===>
    <FooBar2 />
    // error TS2322: Type '{}' is not assignable to type 'IntrinsicAttributes & void & { children?: ReactNode; }'.
    //   Type '{}' is not assignable to type 'void'.

    <FooBar3 />
  </div>,
  document.getElementById('app')
);

With TypeScript 2.2 => no error.

Is it an expected behavior?

@mhegazy mhegazy added this to the TypeScript 2.3.2 milestone Apr 27, 2017
@mhegazy mhegazy added the Bug A bug in TypeScript label Apr 27, 2017
@yuit yuit added Working as Intended The behavior described is the intended behavior; this is not a bug and removed Bug A bug in TypeScript labels Apr 27, 2017
@yuit
Copy link
Contributor

yuit commented Apr 27, 2017

@tkrotoff this is expected. props in React is always empty object even when you don't specify any attribute. Here So with the 2.3 we type empty attributes in JSX Expression the same way (e.g it is an empty object literal) that is why it is not assignable to void.

@tkrotoff
Copy link
Author

@yuit Ok, thx for the answer

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants