From 784ba4cb70c21fb725fdb88b1aad4e07889ede52 Mon Sep 17 00:00:00 2001 From: Nicholas L Date: Thu, 25 Oct 2018 21:40:23 +1300 Subject: [PATCH 1/4] Add test and fix for flowtype for children --- src/createListComponent.js | 4 +++- src/test.js.flow | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/createListComponent.js b/src/createListComponent.js index 916a18bd..28fc7fc5 100644 --- a/src/createListComponent.js +++ b/src/createListComponent.js @@ -15,7 +15,9 @@ type RenderComponentProps = {| isScrolling?: boolean, style: Object, |}; -type RenderComponent = (props: RenderComponentProps) => React$Node; +type RenderComponent = + | React$ComponentType> + | ((props: RenderComponentProps) => React$Node); type ScrollDirection = 'forward' | 'backward'; diff --git a/src/test.js.flow b/src/test.js.flow index 59c665a3..90152671 100644 --- a/src/test.js.flow +++ b/src/test.js.flow @@ -119,6 +119,21 @@ const assertCustomType = (value: ItemData) => {}; ; } +{ + class Item extends React.PureComponent<{ data: void }> { + render() { + const { data } = this.props; + assertVoid(data); + // $FlowFixMe itemData is undefined by default + assertEmpty(data); + return null; + } + } + + {Item} + ; +} + /* FixedSizeGrid */ { From dc49468089d9a1f917df340285c9613090ce9dea Mon Sep 17 00:00:00 2001 From: Nicholas L Date: Thu, 25 Oct 2018 22:01:04 +1300 Subject: [PATCH 2/4] Dont use function with react$node --- src/createListComponent.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/createListComponent.js b/src/createListComponent.js index 28fc7fc5..a03ffb68 100644 --- a/src/createListComponent.js +++ b/src/createListComponent.js @@ -15,9 +15,7 @@ type RenderComponentProps = {| isScrolling?: boolean, style: Object, |}; -type RenderComponent = - | React$ComponentType> - | ((props: RenderComponentProps) => React$Node); +type RenderComponent = React$ComponentType>; type ScrollDirection = 'forward' | 'backward'; From 97eefe0ff46d17faa6c54397d357c2853cc5452a Mon Sep 17 00:00:00 2001 From: Nicholas L Date: Sun, 28 Oct 2018 16:16:43 +1300 Subject: [PATCH 3/4] Fix not using all props. --- src/createListComponent.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/createListComponent.js b/src/createListComponent.js index a03ffb68..29652c56 100644 --- a/src/createListComponent.js +++ b/src/createListComponent.js @@ -15,7 +15,7 @@ type RenderComponentProps = {| isScrolling?: boolean, style: Object, |}; -type RenderComponent = React$ComponentType>; +type RenderComponent = React$ComponentType<$Shape>>; type ScrollDirection = 'forward' | 'backward'; From e48ce2c4c60a27752f45f846a8847b41ebe94644 Mon Sep 17 00:00:00 2001 From: Nicholas L Date: Sun, 28 Oct 2018 16:17:16 +1300 Subject: [PATCH 4/4] Update gridComponent to use ComponentType --- src/createGridComponent.js | 4 +++- src/test.js.flow | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/createGridComponent.js b/src/createGridComponent.js index db796449..fa6ec095 100644 --- a/src/createGridComponent.js +++ b/src/createGridComponent.js @@ -18,7 +18,9 @@ type RenderComponentProps = {| rowIndex: number, style: Object, |}; -export type RenderComponent = (props: RenderComponentProps) => React$Node; +export type RenderComponent = React$ComponentType< + $Shape> +>; type ScrollDirection = 'forward' | 'backward'; diff --git a/src/test.js.flow b/src/test.js.flow index 90152671..65e68f5d 100644 --- a/src/test.js.flow +++ b/src/test.js.flow @@ -261,3 +261,25 @@ const assertCustomType = (value: ItemData) => {}; {Item} ; } + +{ + class Item extends React.PureComponent<{ data: void }> { + render() { + const { data } = this.props; + assertVoid(data); + // $FlowFixMe itemData is undefined by default + assertEmpty(data); + return null; + } + } + + {Item} + ; +}