Calling storage.generateUploadUrl from the client
When I use TSX, this storage.generateUploadUrl api tells me that the argument for the rest parameter "args" was not provided. But when I checked the source code, it didn't seem to require parameters? (and there is really no such problem in js) I want to know what I need to do, such as adding a signature to my mutation function?
7 Replies
my mutation function:
But I can normally get this url on the front end🤣
It looks like the type of generateUploadUrl isn't flowing through to the frontend: (args: any) => Promise<any> is the default type used for a mutation when the actual type is unknown. You're right, it might be better spelled (args?: any) => Promise<any> because the args object (note not a rest parameter) is optional. But it would be especially interesting to figure out why the more specific type is not propagating for you.
To work around you could cast the mutation, but there's something going on here worth fixing. Any other type errors? Is the mutation written in a .js or .ts file?
No additional questions for now, my mutation function is in the TS file, thank you😁
Out of curiosity, does the type inference work if you wrap the function in
{handler: async ({storage})… }
? I had an odd typescript inference failure myselfThe strange thing is that when I pass it as a prop to call this mutation in the child component, it shows an optional parameter like 'arg?.'. And calling directly in the parent component will require me to use a { storageId } parameter
Looking at your code again, I think you trying to call the function in the client code, rather than using the react hook like
useMutation('someFile:generateUploadUrl')
I just made a mutation like yours and the types worked once I passed it into useMutation
so if there's still something funky going on, there's probably some other code causing it.