#Setter type errors
6 messages · Page 1 of 1 (latest)
Have you tried with as const?
return [getter, setter] as const
Yes, I wrote a silly thing, it had nothing to do with that.
i'm pretty sure the type error is on the setter itself, not on the signal return
the resource storage option is not throwing any errors
I should've included a text version of the issue though
type StateSongs = { name: string; rating: number }[];
export const storeBackedSongs: InitializedResourceOptions<
StateSongs,
true
>["storage"] = () => {
const [state, setState] = useGlobal();
const getter: Accessor<StateSongs> = () => state.songs;
const setter: Setter<StateSongs | undefined> = (value) => {
const songs = unwrap(state.songs);
if (typeof value === "function") {
const newSongs = value(songs);
if (newSongs) setState("songs", newSongs);
return newSongs;
}
if (value) setState("songs", value);
return value;
};
return [getter, setter];
};
and the error formatted nicely
type One = <U extends StateSongs | undefined>
| (value: ((prev: StateSongs | undefined) => U)
| Exclude<U, Function>
| ((prev: StateSongs | undefined) => U)) => U;
// not assignable to
type Two = Setter<StateSongs | undefined>
//Target signature provides too few arguments. Expected 1 or more, but got 0.
Well, it's not very clear how it works in the source code either. Where I can only suggest that we make it so ¯_(ツ)_/¯