From 4a9b66aeb32a332e2d5be7e236e5d4567044b3e2 Mon Sep 17 00:00:00 2001
From: Benjamin Canac
Date: Thu, 30 Nov 2023 12:02:37 +0100
Subject: [PATCH] fix(types): improve with strict mode (#1041)
---
.nuxtrc | 1 -
docs/nuxt.config.ts | 3 +++
playground/nuxt.config.ts | 4 +---
src/colors.ts | 2 +-
src/module.ts | 12 ++++++++--
src/runtime/components/data/Table.vue | 8 +++----
src/runtime/components/elements/Accordion.vue | 10 ++++----
src/runtime/components/elements/Alert.vue | 14 +++++------
src/runtime/components/elements/Avatar.vue | 6 ++---
.../components/elements/AvatarGroup.ts | 4 ++--
src/runtime/components/elements/Badge.vue | 6 ++---
src/runtime/components/elements/Button.vue | 6 ++---
.../components/elements/ButtonGroup.ts | 4 ++--
src/runtime/components/elements/Chip.vue | 6 ++---
src/runtime/components/elements/Dropdown.vue | 6 ++---
src/runtime/components/elements/Kbd.vue | 6 ++---
src/runtime/components/elements/Meter.vue | 6 ++---
src/runtime/components/elements/MeterGroup.ts | 10 ++++----
src/runtime/components/elements/Progress.vue | 16 ++++++-------
src/runtime/components/forms/Checkbox.vue | 10 ++++----
src/runtime/components/forms/Form.vue | 2 +-
src/runtime/components/forms/FormGroup.vue | 6 ++---
src/runtime/components/forms/Input.vue | 14 +++++------
src/runtime/components/forms/Radio.vue | 12 +++++-----
src/runtime/components/forms/RadioGroup.vue | 8 +++----
src/runtime/components/forms/Range.vue | 12 +++++-----
src/runtime/components/forms/Select.vue | 12 +++++-----
src/runtime/components/forms/SelectMenu.vue | 16 ++++++-------
src/runtime/components/forms/Textarea.vue | 10 ++++----
src/runtime/components/forms/Toggle.vue | 20 ++++++++--------
src/runtime/components/layout/Card.vue | 6 ++---
src/runtime/components/layout/Container.vue | 6 ++---
src/runtime/components/layout/Divider.vue | 6 ++---
src/runtime/components/layout/Skeleton.vue | 6 ++---
.../components/navigation/Breadcrumb.vue | 6 ++---
.../components/navigation/CommandPalette.vue | 19 ++++++++++-----
.../components/navigation/Pagination.vue | 16 ++++++-------
src/runtime/components/navigation/Tabs.vue | 23 +++++++++++--------
.../navigation/VerticalNavigation.vue | 6 ++---
.../components/overlays/ContextMenu.vue | 6 ++---
src/runtime/components/overlays/Modal.vue | 6 ++---
.../components/overlays/Notification.vue | 12 +++++-----
.../components/overlays/Notifications.vue | 6 ++---
src/runtime/components/overlays/Popover.vue | 6 ++---
src/runtime/components/overlays/Slideover.vue | 6 ++---
src/runtime/components/overlays/Tooltip.vue | 8 +++----
src/runtime/composables/defineShortcuts.ts | 2 +-
src/runtime/composables/useFormGroup.ts | 12 +++++-----
src/runtime/composables/useUI.ts | 2 +-
src/runtime/types/breadcrumb.d.ts | 2 ++
src/runtime/types/form.d.ts | 2 +-
src/runtime/ui.config/data/table.ts | 6 ++---
src/runtime/ui.config/elements/accordion.ts | 4 ++--
src/runtime/ui.config/elements/alert.ts | 10 ++++----
src/runtime/ui.config/elements/dropdown.ts | 4 ++--
src/runtime/ui.config/forms/selectMenu.ts | 4 ++--
src/runtime/ui.config/layout/divider.ts | 4 ++--
.../ui.config/navigation/commandPalette.ts | 2 +-
.../ui.config/navigation/pagination.ts | 14 +++++------
.../navigation/verticalNavigation.ts | 4 ++--
.../ui.config/overlays/notification.ts | 10 ++++----
test/basic.spec.ts | 12 +++++-----
test/components/elements/Button.spec.ts | 1 +
test/components/layout/Skeleton.spec.ts | 1 +
test/nuxt/nuxt.config.ts | 4 +---
test/nuxt/tsconfig.json | 3 ---
tsconfig.json | 6 ++++-
vitest.config.ts | 3 ++-
68 files changed, 266 insertions(+), 242 deletions(-)
delete mode 100644 test/nuxt/tsconfig.json
diff --git a/.nuxtrc b/.nuxtrc
index 87857b2a..f0334199 100644
--- a/.nuxtrc
+++ b/.nuxtrc
@@ -1,3 +1,2 @@
imports.autoImport=false
typescript.includeWorkspace=true
-typescript.strict=false
diff --git a/docs/nuxt.config.ts b/docs/nuxt.config.ts
index 09b1909c..bc6fc7ca 100644
--- a/docs/nuxt.config.ts
+++ b/docs/nuxt.config.ts
@@ -123,5 +123,8 @@ export default defineNuxtConfig({
}
})
}
+ },
+ typescript: {
+ strict: false
}
})
diff --git a/playground/nuxt.config.ts b/playground/nuxt.config.ts
index aecaf090..efab8451 100644
--- a/playground/nuxt.config.ts
+++ b/playground/nuxt.config.ts
@@ -1,7 +1,5 @@
-import module from '../src/module'
-
export default defineNuxtConfig({
modules: [
- module
+ '../src/module'
]
})
diff --git a/src/colors.ts b/src/colors.ts
index b866d24b..a0455fc9 100644
--- a/src/colors.ts
+++ b/src/colors.ts
@@ -243,7 +243,7 @@ export const generateSafelist = (colors: string[], globalColors) => {
}
export const customSafelistExtractor = (prefix, content: string, colors: string[], safelistColors: string[]) => {
- const classes = []
+ const classes: string[] = []
const regex = /<([A-Za-z][A-Za-z0-9]*(?:-[A-Za-z][A-Za-z0-9]*)*)\s+(?![^>]*:color\b)[^>]*\bcolor=["']([^"']+)["'][^>]*>/gs
const matches = content.matchAll(regex)
diff --git a/src/module.ts b/src/module.ts
index 7a636088..febde1e7 100644
--- a/src/module.ts
+++ b/src/module.ts
@@ -10,10 +10,15 @@ import type { DeepPartial, Strategy } from './runtime/types/utils'
const defaultExtractor = createDefaultExtractor({ tailwindConfig: { separator: ':' } })
+// @ts-ignore
delete defaultColors.lightBlue
+// @ts-ignore
delete defaultColors.warmGray
+// @ts-ignore
delete defaultColors.trueGray
+// @ts-ignore
delete defaultColors.coolGray
+// @ts-ignore
delete defaultColors.blueGray
type UI = {
@@ -79,12 +84,15 @@ export default defineNuxtModule({
// @ts-ignore
nuxt.hook('tailwindcss:config', function (tailwindConfig) {
+ tailwindConfig.theme = tailwindConfig.theme || {}
+ tailwindConfig.theme.extend = tailwindConfig.theme.extend || {}
+ tailwindConfig.theme.extend.colors = tailwindConfig.theme.extend.colors || {}
+
const globalColors: any = {
...(tailwindConfig.theme.colors || defaultColors),
...tailwindConfig.theme.extend?.colors
}
- tailwindConfig.theme.extend.colors = tailwindConfig.theme.extend.colors || {}
// @ts-ignore
globalColors.primary = tailwindConfig.theme.extend.colors.primary = {
50: 'rgb(var(--color-primary-50) / )',
@@ -132,7 +140,7 @@ export default defineNuxtModule({
}
tailwindConfig.safelist = tailwindConfig.safelist || []
- tailwindConfig.safelist.push(...generateSafelist(options.safelistColors, colors))
+ tailwindConfig.safelist.push(...generateSafelist(options.safelistColors || [], colors))
tailwindConfig.plugins = tailwindConfig.plugins || []
tailwindConfig.plugins.push(iconsPlugin(Array.isArray(options.icons) || options.icons === 'all' ? { collections: getIconCollections(options.icons) } : typeof options.icons === 'object' ? options.icons as IconsPluginOptions : {}))
diff --git a/src/runtime/components/data/Table.vue b/src/runtime/components/data/Table.vue
index be65e7df..6bdb78a0 100644
--- a/src/runtime/components/data/Table.vue
+++ b/src/runtime/components/data/Table.vue
@@ -11,7 +11,7 @@
,
- default: undefined
+ default: () => ''
},
ui: {
- type: Object as PropType>,
- default: undefined
+ type: Object as PropType & { strategy?: Strategy }>,
+ default: () => ({})
}
},
emits: ['update:modelValue', 'update:sort'],
diff --git a/src/runtime/components/elements/Accordion.vue b/src/runtime/components/elements/Accordion.vue
index 3873bc33..ab930230 100644
--- a/src/runtime/components/elements/Accordion.vue
+++ b/src/runtime/components/elements/Accordion.vue
@@ -93,17 +93,17 @@ export default defineComponent({
},
class: {
type: [String, Object, Array] as PropType,
- default: undefined
+ default: () => ''
},
ui: {
- type: Object as PropType>,
- default: undefined
+ type: Object as PropType & { strategy?: Strategy }>,
+ default: () => ({})
}
},
setup (props) {
const { ui, attrs } = useUI('accordion', toRef(props, 'ui'), config, toRef(props, 'class'))
- const uiButton = computed>(() => configButton)
+ const uiButton = computed(() => configButton)
const buttonRefs = ref<{ open: boolean, close: (e: EventTarget) => {} }[]>([])
@@ -114,7 +114,7 @@ export default defineComponent({
buttonRefs.value.forEach((button) => {
if (button.open) {
- button.close(e.target)
+ button.close(e.target as EventTarget)
}
})
}
diff --git a/src/runtime/components/elements/Alert.vue b/src/runtime/components/elements/Alert.vue
index 13072fdd..e5809b3c 100644
--- a/src/runtime/components/elements/Alert.vue
+++ b/src/runtime/components/elements/Alert.vue
@@ -17,15 +17,15 @@
-
+
-
+
-
+
@@ -73,7 +73,7 @@ export default defineComponent({
},
closeButton: {
type: Object as PropType