v0.40.0
Minor Changes
-
92a38df: Add
defineKeysand infer literalmutationKeytuples indefineMutationwithoutas const.defineMutationnow uses TypeScript 5.0'sconsttype parameter modifier onTMutationKey, mirroring the recent change todefineQuery.mutationKey: ['users', 'create']infers asreadonly ['users', 'create']instead of widening tostring[].// Before defineMutation({ mutationKey: ['users', 'create'] as const, mutationFn: ... }); // After defineMutation({ mutationKey: ['users', 'create'], mutationFn: ... });
defineKeysis a new identity helper for declaring TanStack Query key maps. It uses theconstmodifier to preserve tuple types on static entries, and a strict tuple constraint to narrow factory return shapes withoutas const. Factory bodies still needas constfor literal narrowing of static positions.import { defineKeys } from "wellcrafted/query"; const userKeys = defineKeys({ all: ["users"], // readonly ['users'] active: ["users", "active"], // readonly ['users', 'active'] detail: (id: string) => ["users", id], // [string, string] page: (n: number) => ["users", n] as const, // readonly ['users', number] });
Without
defineKeys, the same map requiresas conston every line. The const modifier on a generic does not reach into function-body return-type inference, which is why factory entries with literal positions like'users'still needas constinside the body to preserve the literal.