From f3c690ebd8b093384573399781ecb8c6942181b5 Mon Sep 17 00:00:00 2001 From: Benjamin Canac Date: Tue, 2 Apr 2024 16:50:25 +0200 Subject: [PATCH] chore(templates): move `DeepPartial` to runtime types chore(templates): up --- src/runtime/types/utils.d.ts | 3 +++ src/templates.ts | 38 ++++++++++++++++-------------------- 2 files changed, 20 insertions(+), 21 deletions(-) create mode 100644 src/runtime/types/utils.d.ts diff --git a/src/runtime/types/utils.d.ts b/src/runtime/types/utils.d.ts new file mode 100644 index 00000000..8170a71d --- /dev/null +++ b/src/runtime/types/utils.d.ts @@ -0,0 +1,3 @@ +export type DeepPartial = Partial<{ + [P in keyof T]: DeepPartial | { [key: string]: string | object } +}> diff --git a/src/templates.ts b/src/templates.ts index ca498f5c..05cb6752 100644 --- a/src/templates.ts +++ b/src/templates.ts @@ -70,30 +70,26 @@ export function addTemplates (options: ModuleOptions, nuxt: Nuxt) { addTypeTemplate({ filename: 'types/ui.d.ts', getContents: () => `import * as ui from '#build/ui' +import type { DeepPartial } from '#ui/types/utils' - type DeepPartial = Partial<{ - [P in keyof T]: DeepPartial | { [key: string]: string | object } - }> +const colors = ${JSON.stringify(options.colors)} as const; - const colors = ${JSON.stringify(options.colors)} as const; +type AppConfigUI = { + primary?: typeof colors[number] + gray?: 'slate' | 'cool' | 'zinc' | 'neutral' | 'stone' +} & DeepPartial - type UI = { - primary?: typeof colors[number] - gray?: 'slate' | 'cool' | 'zinc' | 'neutral' | 'stone' - [key: string]: any - } & DeepPartial - - declare module 'nuxt/schema' { - interface AppConfigInput { - ui?: UI - } - } - declare module '@nuxt/schema' { - interface AppConfigInput { - ui?: UI - } - } - export {} +declare module 'nuxt/schema' { + interface AppConfigInput { + ui?: AppConfigUI + } +} +declare module '@nuxt/schema' { + interface AppConfigInput { + ui?: AppConfigUI + } +} +export {} ` }) }