useStore unwraps mutate boolean input type into conditions and infers never as data type for mutate
I have an issue when passing a boolean as the input type to a mutate query.
https://codesandbox.io/p/sandbox/gpqr4r
If you have a create mutate of a type that has multiple overloads (ie. boolean).
```
export const $publish = createMutatorStore<boolean>(
async ({ data: published }) => {
return fetch("/");
}
);
```
it gets turned into the union of types
```ts
const mutate: ((data: false) => Promise<unknown>) | ((data: true) => Promise<unknown>)
```
and then when doing the inference
```ts
type StoreKeys<T> = T extends { setKey: (k: infer K, v: any) => unknown }
? K
: never
```
T['setKey'] becomes a union of functions, and TypeScript does not infer infer K across all branches cleanly—it bails out and often returns never.
So I have a typing issue when calling the mutate. I can ts-ignore it or cast as never but this definitely confused me and I'm not sure if this is a change or just a documentation gap.
2 条评论