lukemorales/query-key-factory

Don't you need a strict type that only accepts valid factory keys?

Opened this issue · 1 comments

Currently, queryOptions except 'queryKey' | 'queryFn' | 'contextQueries' are omitted.

    const store = createQueryKeyStore({
      users: {
        me: null,
        detail: (userId: string) => ({
          queryKey: [userId],
          refetchInterval: 5000,
          hihi: () => 'hi'
          queryFn: () => Promise.resolve({ id: userId }),
          contextQueries: {
            settings: null,
          },
        }),
      },
    });

In the example above, adding the refetchInterval hihi option does not cause a type warning.
Invalid queryOptions such as hihi are omitted and no error occurs at runtime, making it safe.

However, I think it can cause confusion because it does not work even though I entered a valid option in react-query. is there a reason not to perform strict type checking for queryOption, which is currently not supported, including the refetchInterval option?