relay icon indicating copy to clipboard operation
relay copied to clipboard

TypeScript: Property 'invalidateStore' does not exist on type 'RecordSourceProxy'

Open lukebrandonfarrell opened this issue 3 years ago • 4 comments

When using commitLocalUpdate to invalidate the store the TS compiler throws and error:

Property 'invalidateStore' does not exist on type 'RecordSourceProxy'

You can reproduce by writing the following in a TypeScript project:

commitLocalUpdate(relayEnvironment, (store : RecordSourceProxy) => {
      store.invalidateStore(); // Property 'invalidateStore' does not exist on type 'RecordSourceProxy'
 });

I believe that RecordSourceProxy needs to be updated in updater: StoreUpdater to RecordSourceSelectorProxy.

If someone points me in the right direction on where to make this change, I can make a PR.

lukebrandonfarrell avatar Jul 09 '21 10:07 lukebrandonfarrell

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jan 09 '22 08:01 stale[bot]

A year after, the issue is still there. It's seems to be possible to invalidate store after mutation, but it isn't when using commitLocalUpdate Screenshot 2023-03-14 at 22 55 10

maxprilutskiy avatar Mar 14 '23 21:03 maxprilutskiy

Would be super helpful to have this implemented or for there to be another documented alternative to invalidating the store outside of a mutation or subscription.

vxm5091 avatar Mar 23 '23 08:03 vxm5091

This is already fixed by the typescript implementation here: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/relay-runtime/lib/mutations/commitLocalUpdate.d.ts

And @vxm5091 you should be able to do something like this to invalidating the store:

import { useRelayEnvironment } from 'react-relay/hooks'
import { commitLocalUpdate } from 'react-relay';

export const useInvalidateRelayStore = () => {
  const environment = useRelayEnvironment();
  return () => {
    commitLocalUpdate(environment, store => {
      store.invalidateStore()
    });
  };
}

I think we can close this issue in my opinion.

nossila avatar Jan 12 '24 14:01 nossila