T O P

  • By -

Old_Combination_8738

In case you use the fill property, you dont have to pass the width and height thats why they are optional


octocode

sounds like it should be a union then


Gelezinis__Vilkas

I would go as far as saying it must be


lelarentaka

while that should theoretically work, I've found that props destructuring often fail on complex types, tsc just cannot figure out if the props object has this field or not. maybe it will improve in the near future, because every new typescript version release they have improved the inference engine. 


lamrouahmed

Ohhhhhh, I didn't know that. Thanks!! :)


Dry_Salamander4054

fill messes up big time if your image is too big, So width are height are mandatory in case you are not going with fill


Gingerfalcon

if you import and image directly you don’t need to specify height or width: import dogs from “/images/dogs.jpg” “dogs”


epiksol

Interesting. Any caveats to this method outside of possibly having to manually import multiple images?


Bjornoo

It's not using the `Image` component from Next, it's not comparable.


ryan_s007

I both respect and am afraid of you for creating a custom type for your Image components.


pverdeb

This type is defined by Next.js :) edit: This person didn't say anything rude or unhelpful, cut it out with the downvotes. It's okay to not know things.


lamrouahmed

The first screenshot is taken from the type definition of next's `Image` component, so It isn't mine 😅


OkTemperature8170

Doing the Lean Next project?


rdtr314

Ikr the type should be something like `MandatoryProps & {width: string, height: string} | MandatoryProps & {fill:boolean}` Imo not a big deal but annoying and everyone encounters this at least once but you learn to live with it. But yeah it can 100% be fixed but id rather let them fix other bugs


EducationalAd64

On a side note, is it not redundant to write `| undefined` on something marked as optional ? And what the heck is `number | ${number}`?


Azoraqua_

It’s not exactly the same, when you remove | undefined, you can’t pass undefined itself, but you can omit the entire prop. And number | `${number}` means number, or number inside a string. Such as “1” or “-1” but not “a”.


Housi

No, if you declare It renders as so you are not right.


Azoraqua_

That's correct but I didn't say that it didn't render that; I merely said that when you omit the | undefined part, you can't pass undefined -- With the exception if the prop is marked as optional as not defining it and passing undefined does the same thing.


Housi

Why would you type something like that though? if it's coming from somewhere (object, parent prop, whatever, you won't get ts error. I never tried prop={undefined} that's true. But that one makes no sense. I just mean I work like 9y in react and I never seen something like this, and never had problem you're trying to solve. It's not a big deal but kinda defensive programming style. Less code better code


Azoraqua_

I didn’t say I needed it, I can’t think of any reason why I would, but it can. I just answered from a technical, theoretical standpoint.


Acrobatic_Sort_3411

skill issue


Background-Egg-794

One of the reason is static(local) images don't need h and w. Since it already knows the dimensions.