-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(types): fix type error if nuxtIcon property doesn't exist in appConfig #63
Conversation
|
Well, this is not exactly a chore. This bug currently breaks builds when strict type-checking is enabled! |
Is I do see the intention is to extend |
Perhaps it should be tracked as a nuxt issue. Tbh I'd say having them autogenerated is kind of an anti-pattern. |
Why is that?
It can happen but in 5 years using Nuxt with modules, never happened |
Well, I'd expect modules to explicitly declare the interfaces, so that evolutions of the modules interface are explicitly handled by rigorous type-checking from the module authors, and not found out by users accidentally when updating.
That said, if these cases are very infrequent/never happened, then perhaps it's reasonable to ignore them. |
I think it is necessary, nuxt auto import type only if the nuxtIcon option is defined, we could either manually typing app config or force users to add nuxtIcon option in app.config.ts to resolve this issue. Reference: https://nuxt.com/docs/guide/directory-structure/app-config#manually-typing-app-config |
Thanks for sharing your thoughts. Sorry for asking further, but out of curiosity I'd like to understand as well - is there any module doing this? I missed out that declare module '@nuxt/schema' {
interface AppConfig {
nuxtIcon?: ModuleOptions
}
} Doesn't require any additional imports or exports! See other modules extend NuxtHooks in a similar way like so: https://github.com/nuxt-modules/tailwindcss/blob/05aaa004f5dba3cea4ceb1cd01363b1544af58dc/src/module.ts#L43-L47 |
Moreover, the module also uses the |
I see the problem being raised in the runtime components in the module after changes in #56, and type configuration depends on execution for the hook so I think your solution is suitable except that I would extend the interface in (Please do review the changes and description in #40) |
I got same issue, Found that adding empty object to export default defineAppConfig({
nuxtIcon: {},
}) |
it seems to only work in dev mode :/ |
Did anyone found any solution for this issue? It is breaking the build. :( |
@pratik149 Here's my current workaround: Put the following snippet inside
This way it doesn't break anything for me. |
@atinux Any idea on this? Build breaking... |
@luke-z with that node_modules/nuxt-icon/dist/runtime/Icon.vue:28:33 - error TS7053: Element implicitly has an 'any' type because expression of type 'string & {}' can't be used to index type '{}'.
28 const iconName = computed(() => (appConfig.nuxtIcon?.aliases || {})[props.name] || props.name) |
@chris-lsn do you think this change can be made? I don't see any other issues - eager to push this for a merge 🙂 |
I found a temporary workaround and that is to suppress that typescript error, just so as to not break the build. In your This is how my tsconfig.json looks like {
"extends": "./.nuxt/tsconfig.json",
"compilerOptions": {
"strict": true,
"skipLibCheck": true,
"suppressImplicitAnyIndexErrors": true,
"types": [
"@vueuse/nuxt",
"@pinia/nuxt"
]
}
} |
Temporarily this works for me. // app.config.ts
export interface NuxtIconModuleOptions {
size?: string | false
class?: string
aliases?: { [alias: string]: string }
}
export default defineAppConfig({
nuxtIcon: {
size: '24px', // default <Icon> size applied
class: 'icon', // default <Icon> class applied
aliases: {}
} as NuxtIconModuleOptions
}) |
Does the issue persist in recently released v0.4.0? (or keeping track of PRs mentioning #62) |
Hello yes I confirm that the bug is still present because I just did the test |
related issue
#62