Skip to content

Conversation

kr4chinin
Copy link

I was hyped about this package but when I first installed it and copy-pasted example from the README.md I've got a lot of type errors, I was not able to find a workaround and decided to research the code.

All issues were looking approximately like this:

Type '(userId: string) => string[]' is not assignable to type 'QueryKeyBuilder<[]>'. Target signature provides too few arguments. Expected 1 or more, but got 0.

Example issues

I was encountering them even when I've installed this initial repo.

So what I've decided to change and why with a small help of Cursor:

  • Allow nested maps

    • Before: create expected a flat Record<string, QueryKeyBuilder>, so { users: { list: ... } } made TS think users must be a function, causing “'list' does not exist in type 'QueryKeyBuilder<[]>'”.
    • Now: create accepts a QueryKeyTree (object tree). I added a recursive register that descends into objects and registers any functions it finds. This enables nested namespaces like admin.users.list.
  • Unify stored builder type

    • Before: Registry stored builders with their exact generic types, which made assignability brittle.
    • Now: The registry stores a StoredQueryKeyBuilder of type (...args: unknown[]) => QueryKey. This erases arg specifics for storage, keeping runtime behavior intact while avoiding type incompatibilities.
  • Support any builder arity

    • Before: QueryKeyBuilder defaulted to [] (no args), so single-arg builders failed with “Target signature provides too few arguments.”
    • Now: QueryKeyBuilder defaults to unknown[], so builders with any number/types of args are assignable without casts.

We can now define flat or nested key maps with builders of any arity, and TS no longer complains about unknown properties or argument count mismatches.

Also I've change all any to unknown for more semantic typisation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant