flow/flow-bin

React$ElementConfig converts props to read-only

Closed this issue · 0 comments

LazyPicure.js

type Styles: {
  root: string,
};

type Props = {
  alt: string,
  image: { src: string, preSrc: string },
  styles: ?Styles,
};

const LazyPicture = (props: Props) => { ... }

LazyPicture.defaultProps = {
  styles: null,
};

index.js

import Loadable from 'react-loadable';
import typeof LazyPicture from './LazyPicture';

type Props = React$ElementConfig<LazyPicture>;

const LoadableLazyPicture: React$ComponentType<Props> = Loadable({
  loader: () => import(/* webpackChunkName: "lazy-picture" */ './LazyPicture'),
  loading: () => null,
});

export default LoadableLazyPicture;

Now when I run flow:

capture d ecran 2018-11-30 a 14 15 13

In fact in index.js, type Props from React$ElementConfig became read only:

type Props = {
    +alt: string,
    +image: {
        preSrc: string,
        src: string
    },
    +styles ? : ? Styles
}

I expected to have the same type from React$ElementConfig
I cannot use React$ElementProps because I need to preserve the defaultProps

flow-bin@0.87.0

https://flow.org/en/docs/react/types/#toc-react-elementprops
https://flow.org/en/docs/react/types/#toc-react-elementconfig