lukemorales / query-key-factory

A library for creating typesafe standardized query keys, useful for cache management in @tanstack/query
https://www.npmjs.com/package/@lukemorales/query-key-factory
MIT License
1.24k stars 32 forks source link

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

Open clockk opened 2 months ago

clockk commented 2 months ago

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?

linear[bot] commented 2 months ago

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