nuxt / icon

The <Icon> component, supporting Iconify, Emojis and custom components.

Home Page:https://stackblitz.com/edit/nuxt-icon-playground?file=app.vue

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Type error when `noUncheckedIndexedAccess` is enabled

Tsuyoshi84 opened this issue · comments

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