rt2zz / redux-persist

persist and rehydrate a redux store
MIT License
12.97k stars 867 forks source link

Adding properties to `createStore` causes Flow issues #619

Open ssorallen opened 6 years ago

ssorallen commented 6 years ago

Flow is complaining about "persistStore.js" because it adds properties to the return value of react-redux's createStore. When Objects are created with properties in Flow, they are treated as sealed objects; adding properties like this is not allowed.

flow-bin: 0.57.3 redux-persist: 5.4.0

Error: node_modules/redux-persist/lib/persistStore.js.flow:67
 67:   persistor.purge = () => {
                 ^^^^^ property `purge`. Property not found in
 67:   persistor.purge = () => {
       ^^^^^^^^^ object type

Error: node_modules/redux-persist/lib/persistStore.js.flow:78
 78:   persistor.flush = () => {
                 ^^^^^ property `flush`. Property not found in
 78:   persistor.flush = () => {
       ^^^^^^^^^ object type

Error: node_modules/redux-persist/lib/persistStore.js.flow:89
 89:   persistor.pause = () => {
                 ^^^^^ property `pause`. Property not found in
 89:   persistor.pause = () => {
       ^^^^^^^^^ object type

Error: node_modules/redux-persist/lib/persistStore.js.flow:112
112:     if (boostrappedCb && persistor.getState().bootstrapped) {
                                                   ^^^^^^^^^^^^ property `bootstrapped`. Property not found in possibly undefined value
112:     if (boostrappedCb && persistor.getState().bootstrapped) {
                              ^^^^^^^^^^^^^^^^^^^^ undefined

Error: node_modules/redux-persist/lib/persistStore.js.flow:118
118:   persistor.persist = () => {
                 ^^^^^^^ property `persist`. Property not found in
118:   persistor.persist = () => {
       ^^^^^^^^^ object type

Error: node_modules/redux-persist/lib/persistStore.js.flow:124
124:   return persistor
              ^^^^^^^^^ object type. This type is incompatible with the expected return type of
 44: ): Persistor {
        ^^^^^^^^^ object type
  Property `flush` is incompatible:
     44: ): Persistor {
            ^^^^^^^^^ property `flush`. Property not found in
    124:   return persistor
                  ^^^^^^^^^ object type

Error: node_modules/redux-persist/lib/persistStore.js.flow:124
124:   return persistor
              ^^^^^^^^^ object type. This type is incompatible with the expected return type of
 44: ): Persistor {
        ^^^^^^^^^ object type
  Property `getState` is incompatible:
     25:     getState(): S;
             ^^^^^^^^^^^^^ function type. This type is incompatible with. See lib: flow-typed/npm/redux_v3.x.x.js:25
     80:   +getState: () => PersistorState,
                      ^^^^^^^^^^^^^^^^^^^^ function type. See: node_modules/redux-persist/lib/types.js.flow:80
      This parameter is incompatible:
         65:   let persistor = createStore(persistorReducer, undefined, options.enhancer)
                                                             ^^^^^^^^^ undefined. This type is incompatible with
         80:   +getState: () => PersistorState,
                                ^^^^^^^^^^^^^^ object type. See: node_modules/redux-persist/lib/types.js.flow:80

Error: node_modules/redux-persist/lib/persistStore.js.flow:124
124:   return persistor
              ^^^^^^^^^ object type. This type is incompatible with the expected return type of
 44: ): Persistor {
        ^^^^^^^^^ object type
  Property `purge` is incompatible:
     44: ): Persistor {
            ^^^^^^^^^ property `purge`. Property not found in
    124:   return persistor
                  ^^^^^^^^^ object type

Found 8 errors
Ashoat commented 6 years ago

Seeing this issue too

rt2zz commented 6 years ago

is there any way to unseal an object? We could I think spread it, but that seems an unnecessary cost just for the sake of appeasing flow.

rt2zz commented 6 years ago

also I am confused because I have redux-persist in use in a react-native project using flow 0.57.3 but am not seeing this error. Is there some confounding factor here that I am not aware of?

ssorallen commented 6 years ago

@rt2zz Sorry, I'm no longer working on the project where I saw this error.

ssorallen commented 6 years ago

If no one has a way to easily reproduce this, I'm fine closing it.