Skip to content

Commit 6ddf899

Browse files
fix(types): resolve ambient declaration error in icons type (#4991)
Co-authored-by: Sandro Circi <[email protected]>
1 parent e31f069 commit 6ddf899

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
@@ -201,12 +201,16 @@ export function getTemplates(options: ModuleOptions, uiConfig: Record<string, an
201201
// FIXME: `typeof colors[number]` should include all colors from the theme
202202
templates.push({
203203
filename: 'types/ui.d.ts',
204-
getContents: () => `import * as ui from '#build/ui'
204+
getContents: () => {
205+
const iconKeys = Object.keys(uiConfig?.icons || {})
206+
const iconUnion = iconKeys.length ? iconKeys.map(i => JSON.stringify(i)).join(' | ') : 'string'
207+
208+
return `import * as ui from '#build/ui'
205209
import type { TVConfig } from '@nuxt/ui'
206210
import type { defaultConfig } from 'tailwind-variants'
207211
import colors from 'tailwindcss/colors'
208212
209-
const icons = ${JSON.stringify(uiConfig.icons)};
213+
type IconsConfig = Record<${iconUnion} | (string & {}), string>
210214
211215
type NeutralColor = 'slate' | 'gray' | 'zinc' | 'neutral' | 'stone'
212216
type Color = Exclude<keyof typeof colors, 'inherit' | 'current' | 'transparent' | 'black' | 'white' | NeutralColor> | (string & {})
@@ -216,7 +220,7 @@ type AppConfigUI = {
216220
${options.theme?.colors?.map(color => `'${color}'?: Color`).join('\n\t\t')}
217221
neutral?: NeutralColor | (string & {})
218222
}
219-
icons?: Partial<typeof icons>
223+
icons?: Partial<IconsConfig>
220224
tv?: typeof defaultConfig
221225
} & TVConfig<typeof ui>
222226
@@ -232,6 +236,7 @@ declare module '@nuxt/schema' {
232236
233237
export {}
234238
`
239+
}
235240
})
236241

237242
templates.push({

0 commit comments

Comments
 (0)