Skip to content

Instantly share code, notes, and snippets.

@jameskraus
Last active November 9, 2017 20:05
Show Gist options
  • Save jameskraus/5e7c629e85f13388ee6a669a70a065a9 to your computer and use it in GitHub Desktop.
Save jameskraus/5e7c629e85f13388ee6a669a70a065a9 to your computer and use it in GitHub Desktop.
// @flow
import React from 'react'
import ReactDom from 'react-dom'
class InnerComponent extends React.Component<void, { myVal: number }, void>{
props: { myVal: number }
render = () =>
<div>
My value is {this.props.myVal}
</div>
}
const HOC = <T>(Comp: Class<React.Component<any, { myVal: T}, any>>) =>
({xs}: {xs: Array<T>}) =>
<div>
{xs.forEach(x => <Comp myVal={x} />)}
</div>
const ListComponent = HOC(InnerComponent)
const ListOfValues = [1,2,3]
ReactDom.render(<ListComponent xs={ListOfValues} />, document.getElementById('test'))
@jameskraus
Copy link
Author

Error given by flow:

index.js:26
 26: ReactDom.render(<ListComponent xs={ListOfValues} />, document.getElementById('test'))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ React element `ListComponent`
 17:     ({xs}: {xs: Array<T>}) =>
                           ^ T. This type is incompatible with
 17:     ({xs}: {xs: Array<T>}) =>
                           ^ some incompatible instantiation of `T`

index.js:26
 26: ReactDom.render(<ListComponent xs={ListOfValues} />, document.getElementById('test'))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ React element `ListComponent`
 24: const ListOfValues = [1,2,3]
                           ^ number. This type is incompatible with
 17:     ({xs}: {xs: Array<T>}) =>
                           ^ some incompatible instantiation of `T`

index.js:26
 26: ReactDom.render(<ListComponent xs={ListOfValues} />, document.getElementById('test'))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ React element `ListComponent`
 24: const ListOfValues = [1,2,3]
                             ^ number. This type is incompatible with
 17:     ({xs}: {xs: Array<T>}) =>
                           ^ some incompatible instantiation of `T`

index.js:26
 26: ReactDom.render(<ListComponent xs={ListOfValues} />, document.getElementById('test'))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ React element `ListComponent`
 24: const ListOfValues = [1,2,3]
                               ^ number. This type is incompatible with
 17:     ({xs}: {xs: Array<T>}) =>
                           ^ some incompatible instantiation of `T`


Found 4 errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment