nuxt / image

Plug-and-play image optimization for Nuxt applications.
https://image.nuxt.com
MIT License
1.34k stars 270 forks source link

Object is possibly 'undefined' #1453

Open 9mm opened 2 months ago

9mm commented 2 months ago

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/@nuxt+image@1.7.1_ioredis@5.4.1_magicast@0.3.5_rollup@4.21.1/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>
danielislas3 commented 2 months ago

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.