Modifying the type of mutateAsync's
I'm doing an optimistic update when adding an entry to a table and calling
mutateAsync
with partial data for that entry. However, the type for the variables
of the mutateAsync
function seem to be the same as each element in my useQuery
result, and this gives me a type error, because I'm leaving out a bunch of fields that the database will eventually default to.
Specifically, I have this:
DataExport
requires certain keys, but if I leave those out, Drizzle will set defaults, so I want variables
to be of DataExportInsert
instead.
I tried explicitly setting the type like this:
...but that gives me a new error, ultimately saying Types of parameters variables and variables are incompatible.
.
So for now, I just explicitly set all the optional variables to null
like Drizzle will end up doing, but I wonder if there's a better way to set the type.2 Replies
sensitive-blueOP•2y ago
I.e. I'm doing this (with
addDataExport
being the mutateAsync
function:
...when I'd rather be doing this:
Hmm, looks like it's the type on onMutate
that it uses.
So I did this:
I did have to type old
in setQueryData
as DataExportInsert[]
even though technically it's mostly DataExport[]
(i.e. useQuery TData), which feels a little off, but it works.robust-apricot•2y ago
Can you do an minimal typescript playground?