Skip to content

Commit 526cb81

Browse files
vitpetricaksandros94
authored andcommitted
fix(types): resolve ambient declaration error in icons type (#4991)
Co-authored-by: Sandro Circi <[email protected]>
1 parent 7da16e2 commit 526cb81

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/templates.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,16 @@ export function getTemplates(options: ModuleOptions, uiConfig: Record<string, an
162162
// FIXME: `typeof colors[number]` should include all colors from the theme
163163
templates.push({
164164
filename: 'types/ui.d.ts',
165-
getContents: () => `import * as ui from '#build/ui'
165+
getContents: () => {
166+
const iconKeys = Object.keys(uiConfig?.icons || {})
167+
const iconUnion = iconKeys.length ? iconKeys.map(i => JSON.stringify(i)).join(' | ') : 'string'
168+
169+
return `import * as ui from '#build/ui'
166170
import type { TVConfig } from '@nuxt/ui'
167171
import type { defaultConfig } from 'tailwind-variants'
168172
import colors from 'tailwindcss/colors'
169173
170-
const icons = ${JSON.stringify(uiConfig.icons)};
174+
type IconsConfig = Record<${iconUnion} | (string & {}), string>
171175
172176
type NeutralColor = 'slate' | 'gray' | 'zinc' | 'neutral' | 'stone'
173177
type Color = Exclude<keyof typeof colors, 'inherit' | 'current' | 'transparent' | 'black' | 'white' | NeutralColor> | (string & {})
@@ -177,7 +181,7 @@ type AppConfigUI = {
177181
${options.theme?.colors?.map(color => `'${color}'?: Color`).join('\n\t\t')}
178182
neutral?: NeutralColor | (string & {})
179183
}
180-
icons?: Partial<typeof icons>
184+
icons?: Partial<IconsConfig>
181185
tv?: typeof defaultConfig
182186
} & TVConfig<typeof ui>
183187
@@ -193,6 +197,7 @@ declare module '@nuxt/schema' {
193197
194198
export {}
195199
`
200+
}
196201
})
197202

198203
templates.push({

0 commit comments

Comments
 (0)