final-form / react-final-form-arrays

A component for rendering and editing arrays 🏁 React Final Form
MIT License
205 stars 70 forks source link

Flow types: intersecting inexact shape types is too buggy, causes errors in userland with more recent versions of flow #151

Open jedwards1211 opened 4 years ago

jedwards1211 commented 4 years ago

Let me know if you want a PR...I think we need to investigate workarounds before we proceed...

I'm getting errors like this:

Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ src/universal/components/CalibrationForm/index.js:119:10

Cannot create FieldArray element because property defaultValue is missing in object type [1] but exists in props [2].

     src/universal/components/CalibrationForm/index.js
     116│
     117│     if (isInCalibration) {
     118│       return (
 [2] 119│         <FieldArray
     120│           name="points"
     121│           key={numPoints + 1}
     122│           validate={validatePoints}
     123│           render={props => (
     124│             <CalibrationTable
     125│               {...props}
     126│               units={units}
     127│               rawInputUnits={rawInputUnits}
     128│               bodyClass={classes.body}
     129│             />
     130│           )}
     131│         />

     node_modules/react-final-form-arrays/dist/types.js.flow
 [1]  43│ export type RenderableProps<T> = $Shape<{
      44│   children: (props: T) => React.Node,
      45│   component: React.ComponentType<*>,
      46│   render: (props: T) => React.Node
      47│ }>

Problem is here: https://github.com/final-form/react-final-form-arrays/blob/16f19c538acb62f0410ad6aaf69ccd386fded0a0/src/types.js.flow#L57

Intersecting inexact shape types in Flow has always caused problems like this sporadically.

It seems like this appears to work, though I don't trust it until I've played with it more:

type FieldArrayProps = { name: string, ...$Exact<UseFieldArrayConfig>, ...$Exact<RenderableProps<FieldArrayProps>> }

I don't trust it until I've played with it more though, because I remember seeing inexact spreads like { name: string, ...UseFieldArrayConfig } produce buggy errors (https://github.com/facebook/flow/issues/1326#issuecomment-523286703).

jedwards1211 commented 4 years ago

It's reproducible in try flow:

https://flow.org/try/#0PTAEAEDMBsHsHcBQBLAtgB1gJwC6gFSgCGAzqAEoCmRAxnpFrKqAORbV0uI4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MYK6fVBl+nkIhBiGPCWXGA3XseEE1qAjigAAZKArWUO1nWhj1fWk2s4aFUQ5mUNjJDDFTmOM9GsYkHV+mNYZ-rox1mNswATANaxgSekGmNFbniJ570lX5nNddzWBs4FHBVZF0XpfFai-FYlWpYbmXZbl+UmYVKu81Y6uhpr2sVbr4X66q02jeoE0i1NCgzWN82UIty1rZ9W0IjtKh7ZHR2Mba52XdA703f9cLPg9JostaL3FIyqFKd9v3-dAgOfSDBxHDgdYVkUUMwwX8OIy0MXifQtiOyL1NY7zUt4+BrCpLALB1hMSPt4YMS2OL3cFL3EsDzLVgsCPY-ps6QA

jedwards1211 commented 4 years ago

Also the $Shape around Meta is unnecessary since all properties in it are optional anyway

Nikola-Andreev commented 3 years ago

The solution for me was to downgrade from 3.1.3 to 3.1.1 Please take care about it so in future we can use the newest versions.