Argument of type '"top"' is not assignable to parameter of type 'ImageGravity | undefined'.ts(2345)
- 0
- Databases
- Functions
- Web
- Storage
Hi there! Can someone take a look at my code? I followed the steps from the instruction video, and yet this error appeared out of nowhere. The error is what I mentioned in the title.
The first image is what TypeScript was complaining about. The second one is the console tab when I tried to create a post with an image. Despite that there was no post created in the Post Collection, but the image was saved to the Media Storage.
I am TS noob so any help would be appreciated! Thanks in advance.
If you hover over the function, it'll tell you what parameters it expects. You can also try to use the auto complete to have the IDE suggest what you should put.
The required one was the Gravity, which I declared as "top" but idk what caused the error. However, I did somehow manage to fix the function by deleted the "async" in front of the function. Still, the error stays remain but the function actually works and I now can create posts. But as you mentioned about the parameters, is it required to declare all the parameters or just the ones that I feel needed? Here is all the parameters + the error still there:
Somehow the function worked -> post and image was saved to the database:
Notice how the parameter type is Gravity
unlike bucketId that says string
. So you should be passing in a Gravity and not a string
Did you try the auto complete?
About required or not, the function signature will tell you. Some have ?with the type. That means it's optional. But in JavaScript, you can't just skip over a positional argument; you must pass something. So, you can pass undefined
Oh, I see. Let me try that
I think I did but nothing was shown
What did you do and what did you see?
I'm confused. Is this what you are talking about?
About the type is Gravity
, this is the first time I heard about this one so still don't know what and how to deal with it. Sry about that.
Yes so select that and then what do you see?
This is what I saw
Kind of similar to the previous one
press .
ImageGravity
is a type so you can't pass it like a value.
Ahh I see
Hey, it actually works properly now. Thanks a lot, Steven!
Recommended threads
- 500 Internal Error
Can't access any page in the dashboard
- document.update
Invalid relationship value! The data I'm passing is not null and all the rest I'm just updating the document and not the relationship
- Cannot create documents with encrypted a...
Hello. I wonder if nobody actually uses these things, however: If you create an string attribute through the API with encrypt: true (why only the api..?), th...