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
- The current user is not authorized to pe...
I want to create a document associated with user after log in with OAuth. The user were logged in, but Appwrite said user is unauthorized. User is logged in wi...
- self-hosted auth: /v1/account 404 on saf...
Project created in React/Next.js, Appwrite version 1.6.0. Authentication works in all browsers except Safari (ios), where an attempt to connect to {endpoint}/v1...
- delete document problems
i don't know what's going on but i get an attribute "tournamentid" not found in the collection when i try to delet the document... but this is just the document...