Back

Argument of type '"top"' is not assignable to parameter of type 'ImageGravity | undefined'.ts(2345)

  • 0
  • Databases
  • Functions
  • Web
  • Storage
Taylor
9 May, 2024, 14:04

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.

TL;DR
- Developers discuss passing Type 'ImageGravity' as a value. - Use `.` to explore available options. - Make sure to match 'Gravity' parameter type, not a string. - You can pass 'undefined' for optional parameters. - Removing 'async' fixed saving image to the database. - Errors remain but function works; posts can now be created.
Steven
9 May, 2024, 14:50

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.

Taylor
9 May, 2024, 15:28

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:

Taylor
9 May, 2024, 15:30

Somehow the function worked -> post and image was saved to the database:

Steven
9 May, 2024, 15:30

Notice how the parameter type is Gravity unlike bucketId that says string. So you should be passing in a Gravity and not a string

Steven
9 May, 2024, 15:30

Did you try the auto complete?

Steven
9 May, 2024, 15:32

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

Taylor
9 May, 2024, 15:34

Oh, I see. Let me try that

Taylor
9 May, 2024, 15:34

I think I did but nothing was shown

Steven
9 May, 2024, 15:34

What did you do and what did you see?

Taylor
9 May, 2024, 15:37

I'm confused. Is this what you are talking about?

Taylor
9 May, 2024, 15:38

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.

Steven
9 May, 2024, 15:42

Yes so select that and then what do you see?

Taylor
9 May, 2024, 15:47

This is what I saw

Taylor
9 May, 2024, 15:48

Kind of similar to the previous one

Steven
9 May, 2024, 15:56

press .

Steven
9 May, 2024, 15:58

ImageGravity is a type so you can't pass it like a value.

Taylor
9 May, 2024, 15:59

Ahh I see

Taylor
9 May, 2024, 16:00

Hey, it actually works properly now. Thanks a lot, Steven!

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more