From 021e9a8a93ff47be0d3da258dded8c751997baec Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Mon, 15 Aug 2022 20:31:51 +0800 Subject: [PATCH] refactor: refine emits type declaration Signed-off-by: Ryan Wang --- packages/components/src/components/alert/Alert.vue | 4 +++- packages/components/src/components/button/Button.vue | 4 +++- packages/components/src/components/checkbox/CheckBox.vue | 5 ++++- .../components/src/components/checkbox/CheckBoxGroup.vue | 5 ++++- packages/components/src/components/dialog/Dialog.vue | 5 ++++- packages/components/src/components/input/Input.vue | 4 +++- packages/components/src/components/menu/MenuItem.vue | 4 +++- packages/components/src/components/modal/Modal.vue | 5 ++++- .../components/src/components/pagination/Pagination.vue | 6 +++++- packages/components/src/components/radio/Radio.vue | 5 ++++- packages/components/src/components/radio/RadioGroup.vue | 5 ++++- packages/components/src/components/select/Select.vue | 4 +++- packages/components/src/components/switch/Switch.vue | 5 ++++- packages/components/src/components/tabs/Tabbar.vue | 5 ++++- packages/components/src/components/tabs/Tabs.vue | 5 ++++- packages/components/src/components/textarea/Textarea.vue | 4 +++- .../components/AttachmentAliOSSStrategyEditingModal.vue | 5 ++++- .../attachments/components/AttachmentDetailModal.vue | 5 ++++- .../components/AttachmentLocalStrategyEditingModal.vue | 5 ++++- .../attachments/components/AttachmentSelectModal.vue | 5 ++++- .../attachments/components/AttachmentStrategiesModal.vue | 6 +++++- .../attachments/components/AttachmentUploadModal.vue | 5 ++++- .../posts/categories/components/CategoryEditingModal.vue | 5 ++++- src/modules/contents/posts/components/PostSettingModal.vue | 7 ++++++- .../contents/posts/tags/components/TagEditingModal.vue | 6 +++++- .../interface/menus/components/MenuEditingModal.vue | 5 ++++- .../interface/menus/components/MenuItemEditingModal.vue | 6 +++++- .../interface/menus/components/MenuItemListItem.vue | 6 +++++- src/modules/interface/menus/components/MenuList.vue | 5 ++++- .../interface/themes/components/ThemeInstallModal.vue | 5 ++++- src/modules/interface/themes/components/ThemeListModal.vue | 6 +++++- .../system/plugins/components/PluginInstallModal.vue | 5 ++++- src/modules/system/roles/components/RoleEditingModal.vue | 5 ++++- src/modules/system/users/components/UserEditingModal.vue | 5 ++++- .../system/users/components/UserPasswordChangeModal.vue | 6 +++++- 35 files changed, 143 insertions(+), 35 deletions(-) diff --git a/packages/components/src/components/alert/Alert.vue b/packages/components/src/components/alert/Alert.vue index ee56a7f6..63a6cf27 100644 --- a/packages/components/src/components/alert/Alert.vue +++ b/packages/components/src/components/alert/Alert.vue @@ -31,7 +31,9 @@ const props = withDefaults( } ); -const emit = defineEmits(["close"]); +const emit = defineEmits<{ + (event: "close"): void; +}>(); const classes = computed(() => { return [`alert-${props.type}`]; diff --git a/packages/components/src/components/button/Button.vue b/packages/components/src/components/button/Button.vue index 1fd20def..7221d345 100644 --- a/packages/components/src/components/button/Button.vue +++ b/packages/components/src/components/button/Button.vue @@ -61,7 +61,9 @@ const props = withDefaults( ); const router = useRouter(); -const emit = defineEmits(["click"]); +const emit = defineEmits<{ + (event: "click"): void; +}>(); const classes = computed(() => { return [ diff --git a/packages/components/src/components/checkbox/CheckBox.vue b/packages/components/src/components/checkbox/CheckBox.vue index be671fd9..6fba8e9c 100644 --- a/packages/components/src/components/checkbox/CheckBox.vue +++ b/packages/components/src/components/checkbox/CheckBox.vue @@ -15,7 +15,10 @@ const id = ["checkbox", props.name, props.value] .filter((item) => !!item) .join("-"); -const emit = defineEmits(["update:checked", "change"]); +const emit = defineEmits<{ + (event: "update:checked", value: boolean): void; + (event: "change", value: Event): void; +}>(); function handleChange(e: Event) { const { checked } = e.target as HTMLInputElement; diff --git a/packages/components/src/components/checkbox/CheckBoxGroup.vue b/packages/components/src/components/checkbox/CheckBoxGroup.vue index 638fbd71..27a411df 100644 --- a/packages/components/src/components/checkbox/CheckBoxGroup.vue +++ b/packages/components/src/components/checkbox/CheckBoxGroup.vue @@ -16,7 +16,10 @@ const props = withDefaults( } ); -const emit = defineEmits(["update:modelValue", "change"]); +const emit = defineEmits<{ + (event: "update:modelValue", value: string[]): void; + (event: "change", value: string[]): void; +}>(); function handleChange(e: Event) { const { value, checked } = e.target as HTMLInputElement; diff --git a/packages/components/src/components/dialog/Dialog.vue b/packages/components/src/components/dialog/Dialog.vue index e9f8f6a3..52c77553 100644 --- a/packages/components/src/components/dialog/Dialog.vue +++ b/packages/components/src/components/dialog/Dialog.vue @@ -35,7 +35,10 @@ const props = withDefaults( } ); -const emit = defineEmits(["update:visible", "close"]); +const emit = defineEmits<{ + (event: "update:visible", visible: boolean): void; + (event: "close"): void; +}>(); const icons = { success: { diff --git a/packages/components/src/components/input/Input.vue b/packages/components/src/components/input/Input.vue index 950b2b56..958bb629 100644 --- a/packages/components/src/components/input/Input.vue +++ b/packages/components/src/components/input/Input.vue @@ -15,7 +15,9 @@ const props = withDefaults( } ); -const emit = defineEmits(["update:modelValue"]); +const emit = defineEmits<{ + (event: "update:modelValue", value: string): void; +}>(); const classes = computed(() => { return [`input-${props.size}`]; diff --git a/packages/components/src/components/menu/MenuItem.vue b/packages/components/src/components/menu/MenuItem.vue index 21ecd84c..341b6adf 100644 --- a/packages/components/src/components/menu/MenuItem.vue +++ b/packages/components/src/components/menu/MenuItem.vue @@ -15,7 +15,9 @@ const props = withDefaults( } ); -const emit = defineEmits(["select"]); +const emit = defineEmits<{ + (event: "select", id: string): void; +}>(); const slots = useSlots(); diff --git a/packages/components/src/components/modal/Modal.vue b/packages/components/src/components/modal/Modal.vue index 8df24401..a083fc7d 100644 --- a/packages/components/src/components/modal/Modal.vue +++ b/packages/components/src/components/modal/Modal.vue @@ -17,7 +17,10 @@ const props = withDefaults( } ); -const emit = defineEmits(["update:visible", "close"]); +const emit = defineEmits<{ + (event: "update:visible", value: boolean): void; + (event: "close"): void; +}>(); const rootVisible = ref(false); const modelWrapper = ref(); diff --git a/packages/components/src/components/pagination/Pagination.vue b/packages/components/src/components/pagination/Pagination.vue index f5500026..0aa41aed 100644 --- a/packages/components/src/components/pagination/Pagination.vue +++ b/packages/components/src/components/pagination/Pagination.vue @@ -20,7 +20,11 @@ const { page, size, total } = toRefs(props); const key = ref(Math.random()); -const emit = defineEmits(["update:page", "update:size", "change"]); +const emit = defineEmits<{ + (event: "update:page", page: number): void; + (event: "update:size", size: number): void; + (event: "change", value: { page: number; size: number }): void; +}>(); const onPageChange = ({ currentPage, diff --git a/packages/components/src/components/radio/Radio.vue b/packages/components/src/components/radio/Radio.vue index 8aae291b..606e3dfe 100644 --- a/packages/components/src/components/radio/Radio.vue +++ b/packages/components/src/components/radio/Radio.vue @@ -8,7 +8,10 @@ const props = defineProps<{ name?: string; }>(); -const emit = defineEmits(["update:modelValue", "change"]); +const emit = defineEmits<{ + (event: "update:modelValue", value: string | number | boolean): void; + (event: "change", value: string | number | boolean): void; +}>(); const id = ["radio", props.name, props.value] .filter((item) => !!item) diff --git a/packages/components/src/components/radio/RadioGroup.vue b/packages/components/src/components/radio/RadioGroup.vue index 761e2596..0afe90f9 100644 --- a/packages/components/src/components/radio/RadioGroup.vue +++ b/packages/components/src/components/radio/RadioGroup.vue @@ -15,7 +15,10 @@ withDefaults( } ); -const emit = defineEmits(["update:modelValue", "change"]); +const emit = defineEmits<{ + (event: "update:modelValue", value: string | number | boolean): void; + (event: "change", value: string | number | boolean): void; +}>(); function handleChange(value: string | number | boolean) { emit("update:modelValue", value); diff --git a/packages/components/src/components/select/Select.vue b/packages/components/src/components/select/Select.vue index 2d02db17..772797ce 100644 --- a/packages/components/src/components/select/Select.vue +++ b/packages/components/src/components/select/Select.vue @@ -15,7 +15,9 @@ const props = withDefaults( } ); -const emit = defineEmits(["update:modelValue"]); +const emit = defineEmits<{ + (event: "update:modelValue", value: string): void; +}>(); const classes = computed(() => { return [`select-${props.size}`]; diff --git a/packages/components/src/components/switch/Switch.vue b/packages/components/src/components/switch/Switch.vue index aa53af5a..443659a6 100644 --- a/packages/components/src/components/switch/Switch.vue +++ b/packages/components/src/components/switch/Switch.vue @@ -8,7 +8,10 @@ const props = withDefaults( } ); -const emit = defineEmits(["update:modelValue", "change"]); +const emit = defineEmits<{ + (event: "update:modelValue", value: boolean): void; + (event: "change", value: boolean): void; +}>(); const handleChange = () => { emit("update:modelValue", !props.modelValue); diff --git a/packages/components/src/components/tabs/Tabbar.vue b/packages/components/src/components/tabs/Tabbar.vue index c1d6033b..6ca60540 100644 --- a/packages/components/src/components/tabs/Tabbar.vue +++ b/packages/components/src/components/tabs/Tabbar.vue @@ -19,7 +19,10 @@ const props = withDefaults( } ); -const emit = defineEmits(["update:activeId", "change"]); +const emit = defineEmits<{ + (event: "update:activeId", value: number | string): void; + (event: "change", value: number | string): void; +}>(); const classes = computed(() => { return [`tabbar-${props.type}`, `tabbar-direction-${props.direction}`]; diff --git a/packages/components/src/components/tabs/Tabs.vue b/packages/components/src/components/tabs/Tabs.vue index e8a32ec2..160a70e7 100644 --- a/packages/components/src/components/tabs/Tabs.vue +++ b/packages/components/src/components/tabs/Tabs.vue @@ -25,7 +25,10 @@ provide>( computed(() => props.activeId) ); -const emit = defineEmits(["update:activeId", "change"]); +const emit = defineEmits<{ + (event: "update:activeId", value: number | string): void; + (event: "change", value: number | string): void; +}>(); const slots = useSlots(); diff --git a/packages/components/src/components/textarea/Textarea.vue b/packages/components/src/components/textarea/Textarea.vue index 62bb8a21..0877e6ea 100644 --- a/packages/components/src/components/textarea/Textarea.vue +++ b/packages/components/src/components/textarea/Textarea.vue @@ -12,7 +12,9 @@ withDefaults( } ); -const emit = defineEmits(["update:modelValue"]); +const emit = defineEmits<{ + (event: "update:modelValue", value: string): void; +}>(); function handleInput(e: Event) { const { value } = e.target as HTMLInputElement; diff --git a/src/modules/contents/attachments/components/AttachmentAliOSSStrategyEditingModal.vue b/src/modules/contents/attachments/components/AttachmentAliOSSStrategyEditingModal.vue index 9d0e0cb8..52c4b810 100644 --- a/src/modules/contents/attachments/components/AttachmentAliOSSStrategyEditingModal.vue +++ b/src/modules/contents/attachments/components/AttachmentAliOSSStrategyEditingModal.vue @@ -10,7 +10,10 @@ withDefaults( } ); -const emit = defineEmits(["update:visible", "close"]); +const emit = defineEmits<{ + (event: "update:visible", visible: boolean): void; + (event: "close"): void; +}>(); const onVisibleChange = (visible: boolean) => { emit("update:visible", visible); diff --git a/src/modules/contents/attachments/components/AttachmentDetailModal.vue b/src/modules/contents/attachments/components/AttachmentDetailModal.vue index 4646d87b..b7128057 100644 --- a/src/modules/contents/attachments/components/AttachmentDetailModal.vue +++ b/src/modules/contents/attachments/components/AttachmentDetailModal.vue @@ -17,7 +17,10 @@ withDefaults( } ); -const emit = defineEmits(["update:visible", "close"]); +const emit = defineEmits<{ + (event: "update:visible", visible: boolean): void; + (event: "close"): void; +}>(); const onVisibleChange = (visible: boolean) => { emit("update:visible", visible); diff --git a/src/modules/contents/attachments/components/AttachmentLocalStrategyEditingModal.vue b/src/modules/contents/attachments/components/AttachmentLocalStrategyEditingModal.vue index 4c443486..589c5469 100644 --- a/src/modules/contents/attachments/components/AttachmentLocalStrategyEditingModal.vue +++ b/src/modules/contents/attachments/components/AttachmentLocalStrategyEditingModal.vue @@ -10,7 +10,10 @@ withDefaults( } ); -const emit = defineEmits(["update:visible", "close"]); +const emit = defineEmits<{ + (event: "update:visible", visible: boolean): void; + (event: "close"): void; +}>(); const onVisibleChange = (visible: boolean) => { emit("update:visible", visible); diff --git a/src/modules/contents/attachments/components/AttachmentSelectModal.vue b/src/modules/contents/attachments/components/AttachmentSelectModal.vue index 76db7c1f..b6625632 100644 --- a/src/modules/contents/attachments/components/AttachmentSelectModal.vue +++ b/src/modules/contents/attachments/components/AttachmentSelectModal.vue @@ -10,7 +10,10 @@ withDefaults( } ); -const emit = defineEmits(["update:visible", "close"]); +const emit = defineEmits<{ + (event: "update:visible", visible: boolean): void; + (event: "close"): void; +}>(); const attachments = Array.from(new Array(50), (_, index) => index).map( (index) => { diff --git a/src/modules/contents/attachments/components/AttachmentStrategiesModal.vue b/src/modules/contents/attachments/components/AttachmentStrategiesModal.vue index ad5aa491..8819e1d4 100644 --- a/src/modules/contents/attachments/components/AttachmentStrategiesModal.vue +++ b/src/modules/contents/attachments/components/AttachmentStrategiesModal.vue @@ -18,7 +18,11 @@ withDefaults( visible: false, } ); -const emit = defineEmits(["update:visible", "close"]); + +const emit = defineEmits<{ + (event: "update:visible", visible: boolean): void; + (event: "close"): void; +}>(); const strategies = ref([ { diff --git a/src/modules/contents/attachments/components/AttachmentUploadModal.vue b/src/modules/contents/attachments/components/AttachmentUploadModal.vue index d4a08adf..cf36c40c 100644 --- a/src/modules/contents/attachments/components/AttachmentUploadModal.vue +++ b/src/modules/contents/attachments/components/AttachmentUploadModal.vue @@ -17,7 +17,10 @@ withDefaults( } ); -const emit = defineEmits(["update:visible", "close"]); +const emit = defineEmits<{ + (event: "update:visible", visible: boolean): void; + (event: "close"): void; +}>(); const strategies = ref([ { diff --git a/src/modules/contents/posts/categories/components/CategoryEditingModal.vue b/src/modules/contents/posts/categories/components/CategoryEditingModal.vue index 9c2ac242..7c44c9ac 100644 --- a/src/modules/contents/posts/categories/components/CategoryEditingModal.vue +++ b/src/modules/contents/posts/categories/components/CategoryEditingModal.vue @@ -12,7 +12,10 @@ withDefaults( } ); -const emit = defineEmits(["update:visible", "close"]); +const emit = defineEmits<{ + (event: "update:visible", visible: boolean): void; + (event: "close"): void; +}>(); const onVisibleChange = (visible: boolean) => { emit("update:visible", visible); diff --git a/src/modules/contents/posts/components/PostSettingModal.vue b/src/modules/contents/posts/components/PostSettingModal.vue index 6d82314e..e2461954 100644 --- a/src/modules/contents/posts/components/PostSettingModal.vue +++ b/src/modules/contents/posts/components/PostSettingModal.vue @@ -27,7 +27,12 @@ const props = withDefaults( } ); -const emit = defineEmits(["update:visible", "close", "previous", "next"]); +const emit = defineEmits<{ + (event: "update:visible", visible: boolean): void; + (event: "close"): void; + (event: "previous"): void; + (event: "next"): void; +}>(); const settingActiveId = ref("general"); const formState = ref({ diff --git a/src/modules/contents/posts/tags/components/TagEditingModal.vue b/src/modules/contents/posts/tags/components/TagEditingModal.vue index 16baf62b..cd992f3f 100644 --- a/src/modules/contents/posts/tags/components/TagEditingModal.vue +++ b/src/modules/contents/posts/tags/components/TagEditingModal.vue @@ -11,7 +11,11 @@ withDefaults( tag: undefined, } ); -const emit = defineEmits(["update:visible", "close"]); + +const emit = defineEmits<{ + (event: "update:visible", visible: boolean): void; + (event: "close"): void; +}>(); const onVisibleChange = (visible: boolean) => { emit("update:visible", visible); diff --git a/src/modules/interface/menus/components/MenuEditingModal.vue b/src/modules/interface/menus/components/MenuEditingModal.vue index a14754b3..dd91d433 100644 --- a/src/modules/interface/menus/components/MenuEditingModal.vue +++ b/src/modules/interface/menus/components/MenuEditingModal.vue @@ -19,7 +19,10 @@ const props = withDefaults( } ); -const emit = defineEmits(["update:visible", "close"]); +const emit = defineEmits<{ + (event: "update:visible", visible: boolean): void; + (event: "close"): void; +}>(); const initialFormState: Menu = { spec: { diff --git a/src/modules/interface/menus/components/MenuItemEditingModal.vue b/src/modules/interface/menus/components/MenuItemEditingModal.vue index fc2a2b20..49954f54 100644 --- a/src/modules/interface/menus/components/MenuItemEditingModal.vue +++ b/src/modules/interface/menus/components/MenuItemEditingModal.vue @@ -19,7 +19,11 @@ const props = withDefaults( } ); -const emit = defineEmits(["update:visible", "close", "saved"]); +const emit = defineEmits<{ + (event: "update:visible", visible: boolean): void; + (event: "close"): void; + (event: "saved", menuItem: MenuItem): void; +}>(); const initialFormState: MenuItem = { spec: { diff --git a/src/modules/interface/menus/components/MenuItemListItem.vue b/src/modules/interface/menus/components/MenuItemListItem.vue index d700699d..e51e29bf 100644 --- a/src/modules/interface/menus/components/MenuItemListItem.vue +++ b/src/modules/interface/menus/components/MenuItemListItem.vue @@ -13,7 +13,11 @@ withDefaults( } ); -const emit = defineEmits(["change", "open-editing", "delete"]); +const emit = defineEmits<{ + (event: "change"): void; + (event: "open-editing", menuItem: MenuTreeItem): void; + (event: "delete", menuItem: MenuTreeItem): void; +}>(); const isDragging = ref(false); diff --git a/src/modules/interface/menus/components/MenuList.vue b/src/modules/interface/menus/components/MenuList.vue index 228bd366..1eb49a41 100644 --- a/src/modules/interface/menus/components/MenuList.vue +++ b/src/modules/interface/menus/components/MenuList.vue @@ -21,7 +21,10 @@ const props = withDefaults( } ); -const emit = defineEmits(["select", "update:selectedMenu"]); +const emit = defineEmits<{ + (event: "select", menu: Menu): void; + (event: "update:selectedMenu", menu: Menu): void; +}>(); const menus = ref([] as Menu[]); const selectedMenuToUpdate = ref(null); diff --git a/src/modules/interface/themes/components/ThemeInstallModal.vue b/src/modules/interface/themes/components/ThemeInstallModal.vue index 385bee55..15a01884 100644 --- a/src/modules/interface/themes/components/ThemeInstallModal.vue +++ b/src/modules/interface/themes/components/ThemeInstallModal.vue @@ -15,7 +15,10 @@ withDefaults( } ); -const emit = defineEmits(["update:visible", "close"]); +const emit = defineEmits<{ + (event: "update:visible", visible: boolean): void; + (event: "close"): void; +}>(); const handleVisibleChange = (visible: boolean) => { emit("update:visible", visible); diff --git a/src/modules/interface/themes/components/ThemeListModal.vue b/src/modules/interface/themes/components/ThemeListModal.vue index ea5a7ffe..b9d02f28 100644 --- a/src/modules/interface/themes/components/ThemeListModal.vue +++ b/src/modules/interface/themes/components/ThemeListModal.vue @@ -26,7 +26,11 @@ withDefaults( } ); -const emit = defineEmits(["update:visible", "close", "update:selectedTheme"]); +const emit = defineEmits<{ + (event: "update:visible", visible: boolean): void; + (event: "close"): void; + (event: "update:selectedTheme", theme: Theme | null): void; +}>(); const themes = ref([]); const themeInstall = ref(false); diff --git a/src/modules/system/plugins/components/PluginInstallModal.vue b/src/modules/system/plugins/components/PluginInstallModal.vue index 75ca14fc..6fc9a2cc 100644 --- a/src/modules/system/plugins/components/PluginInstallModal.vue +++ b/src/modules/system/plugins/components/PluginInstallModal.vue @@ -16,7 +16,10 @@ withDefaults( } ); -const emit = defineEmits(["update:visible", "close"]); +const emit = defineEmits<{ + (event: "update:visible", visible: boolean): void; + (event: "close"): void; +}>(); const dialog = useDialog(); diff --git a/src/modules/system/roles/components/RoleEditingModal.vue b/src/modules/system/roles/components/RoleEditingModal.vue index 09d60d96..ea9a90f5 100644 --- a/src/modules/system/roles/components/RoleEditingModal.vue +++ b/src/modules/system/roles/components/RoleEditingModal.vue @@ -22,7 +22,10 @@ const props = withDefaults( } ); -const emit = defineEmits(["update:visible", "close"]); +const emit = defineEmits<{ + (event: "update:visible", visible: boolean): void; + (event: "close"): void; +}>(); const { roleTemplateGroups, handleRoleTemplateSelect, selectedRoleTemplates } = useRoleTemplateSelection(); diff --git a/src/modules/system/users/components/UserEditingModal.vue b/src/modules/system/users/components/UserEditingModal.vue index 8ffbbc36..a0f6b7d3 100644 --- a/src/modules/system/users/components/UserEditingModal.vue +++ b/src/modules/system/users/components/UserEditingModal.vue @@ -29,7 +29,10 @@ const props = withDefaults( } ); -const emit = defineEmits(["update:visible", "close"]); +const emit = defineEmits<{ + (event: "update:visible", visible: boolean): void; + (event: "close"): void; +}>(); interface FormState { user: User; diff --git a/src/modules/system/users/components/UserPasswordChangeModal.vue b/src/modules/system/users/components/UserPasswordChangeModal.vue index 30110941..db8ac1e9 100644 --- a/src/modules/system/users/components/UserPasswordChangeModal.vue +++ b/src/modules/system/users/components/UserPasswordChangeModal.vue @@ -16,7 +16,11 @@ const props = withDefaults( } ); -const emit = defineEmits(["update:visible", "close"]); +const emit = defineEmits<{ + (event: "update:visible", visible: boolean): void; + (event: "close"): void; +}>(); + const currentUser = inject("currentUser"); interface PasswordChangeFormState {