image icon indicating copy to clipboard operation
image copied to clipboard

Object is possibly 'undefined'

Open 9mm opened this issue 1 year ago • 1 comments

I'm getting a lot of errors for typescript in nuxt image. I am using nuxt v4 compatibility mode if that makes a difference

 ERROR(vue-tsc)  Object is possibly 'undefined'.
 FILE  /Users/zesty/Code/xxx-frontend/node_modules/.pnpm/@[email protected][email protected][email protected][email protected]/node_modules/@nuxt/image/dist/runtime/components/NuxtPicture.vue:20:16

    18 |       :src="sources[lastSourceIndex].src"
    19 |       :sizes="sources[lastSourceIndex].sizes"
  > 20 |       :srcset="sources[lastSourceIndex].srcset"
       |                ^^^^^^^^^^^^^^^^^^^^^^^^
    21 |     >
    22 |   </picture>
    23 | </template>

9mm avatar Aug 28 '24 22:08 9mm

I’m hitting the same issue, and I believe it’s related to the latest release v3.13.0. It seems that there were changes in the types, which might be causing this problem. I found this Vue TypeScript Changes that mentions updates to TypeScript handling, but I’m still unsure how to resolve the issue.

danielislas3 avatar Aug 28 '24 23:08 danielislas3

I think this is an upstream issue then.

@danielroe what would be your opinion? :)

Baroshem avatar Dec 11 '24 14:12 Baroshem

it's not an upstream issue, but it was resolved in https://github.com/nuxt/image/commit/917242a567ffbbb3cd6cf467322252a5cf9194f4.

thanks for investigating! ❤

danielroe avatar Dec 11 '24 14:12 danielroe