nuxt / icon

The <Icon> component, supporting Iconify, Emojis and custom components.
https://stackblitz.com/edit/nuxt-icon-playground?file=app.vue
MIT License
930 stars 51 forks source link

Type error when `noUncheckedIndexedAccess` is enabled #132

Closed Tsuyoshi84 closed 6 months ago

Tsuyoshi84 commented 8 months ago

Environment

Nuxt: 3.9.1 icon: 0.6.8

Bug Description

A type error occurs when the TypeScript compiler option noUncheckedIndexedAccess is enabled.

When the option is enabled, TypeScript considers that the type of the following computed, iconName, is string | undefined

https://github.com/nuxt-modules/icon/blob/0aa6fd707a455ea8c416f73e1b4ef7295e12647e/src/runtime/Icon.vue#L62-L67

And because of that, the following code becomes invalid because nuxtApp.vueApp.component() takes a string value, not string | undefined:

https://github.com/nuxt-modules/icon/blob/0aa6fd707a455ea8c416f73e1b4ef7295e12647e/src/runtime/Icon.vue#L71

image

Reproduction

You can reproduce the error by running "npm run typecheck" in the following environment: https://stackblitz.com/edit/nuxt-icon-playground-q1bjwm?file=nuxt.config.ts