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.16k stars 32 forks source link

Default arguments typed as any #90

Closed vieruuuu closed 2 months ago

vieruuuu commented 4 months ago

https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgYygUwIYzQRQK5pQCeA0mkQM4A0cAKkWGgCYCqFuBxA8mDMBADsKcAL5wAZlAgg4AcgACAGzwBrNCGgZFaCgHoAjpyIBaNSfEZkMaEVkAoO8kEV44iBDgBeFOiwdCpOQUABSybhCyNAh2cLFwAEYYUABccMFmXnAARNguWQCUXgB8adFxcLq65QB6APwx5XGGAWREqQDaZgC6VA2NcM3EAGICqcGFniUAClIgwOwAdOgUEIoAbmjBMFAE+X2ieyJ7dkA

linear[bot] commented 4 months ago

OSS-11 Default arguments typed as any

lukemorales commented 2 months ago

It's Typescript struggling to infer the type of the argument even though you're assigning a string to it. I've seen it happen outside of lib code as well, I would guess it might be related to some tsconfig options. Regardless, the fix is just to add the type to the argument:

const foo = createQueryKeys('foo', {
    bar: (key: string = "test") => ({
        queryKey: [key],
        queryFn: () => Promise.resolve(true)
    })
})