What's the correct type to use for an update function?
I'm trying to do a simple function where I update a record in a table:
When doing this:
I get the error:
Here's my schema
Because I'm using
NewVideo
, it TS expects a url
param, but because the record has already been created, this should already exist.
Should I use something like Partial<NewVideo>
?2 Replies
Yes, it's because
NewVideo
is what is required/optional when inserting something. You could do Partial<Video>
or Partial<NewVideo>
, just note that that will allow anyone using that function to update any of the fields. If you care about which fields, you could use the TypeScript Pick<Video, ...>
and choose which fields to allow (or Omit<Video, ...>
to do the opposite)thanks @Noahh that's good confirmation, I was thinking there might be a Drizzle way, but I'll stick with this for now