From 272b8c76c8d324040720bb1e4b29f5c0353f28f0 Mon Sep 17 00:00:00 2001 From: qiang Date: Tue, 9 Mar 2021 21:24:22 +0800 Subject: [PATCH] fix: some components miss install type (#1547) * fix: some components miss install type * fix: some components miss install type --- packages/col/index.ts | 10 ++++++---- packages/date-picker/index.ts | 11 +++++++---- packages/element-plus/index.ts | 14 +++++++++++--- packages/infinite-scroll/index.ts | 10 ++++++---- packages/message-box/index.ts | 18 ++++++++++-------- packages/message/index.ts | 10 ++++++---- packages/notification/index.ts | 10 ++++++---- packages/option/index.ts | 10 ++++++---- packages/pagination/index.ts | 11 ++++++----- packages/row/index.ts | 10 ++++++---- packages/space/index.ts | 9 ++++----- packages/table-column/index.ts | 10 ++++++---- packages/time-picker/index.ts | 10 ++++++---- packages/utils/types.ts | 2 +- 14 files changed, 87 insertions(+), 58 deletions(-) diff --git a/packages/col/index.ts b/packages/col/index.ts index e839abd1d7..daa70e902f 100644 --- a/packages/col/index.ts +++ b/packages/col/index.ts @@ -1,8 +1,10 @@ -import { App } from 'vue' import Col from './src/col' +import type { SFCWithInstall } from '@element-plus/utils/types' -Col.install = (app: App): void => { - app.component(Col.name, Col) +const _Col: SFCWithInstall = Col as SFCWithInstall + +_Col.install = app => { + app.component(_Col.name, _Col) } -export default Col +export default _Col diff --git a/packages/date-picker/index.ts b/packages/date-picker/index.ts index d91e4e03ee..b5ee38080d 100644 --- a/packages/date-picker/index.ts +++ b/packages/date-picker/index.ts @@ -1,8 +1,11 @@ -import { App } from 'vue' import DatePicker from './src/date-picker' +import type { SFCWithInstall } from '@element-plus/utils/types' -DatePicker.install = (app: App): void => { - app.component(DatePicker.name, DatePicker) +const _DatePicker: SFCWithInstall = DatePicker as SFCWithInstall + +_DatePicker.install = app => { + app.component(_DatePicker.name, _DatePicker) } -export default DatePicker + +export default _DatePicker diff --git a/packages/element-plus/index.ts b/packages/element-plus/index.ts index 0f5df110ef..72b7dbe883 100644 --- a/packages/element-plus/index.ts +++ b/packages/element-plus/index.ts @@ -98,9 +98,17 @@ import { setConfig } from '@element-plus/utils/config' import isServer from '@element-plus/utils/isServer' import dayjs from 'dayjs' +type DWindow = Window & typeof globalThis & { + dayjs?: typeof dayjs +} + // expose Day.js to window to make full bundle i18n work -if (!isServer && !(window as any).dayjs) { - (window as any).dayjs = dayjs +if (!isServer) { + const _window: DWindow = window + + if (!_window.dayjs) { + _window.dayjs = dayjs + } } const version = version_ // version_ to fix tsc issue @@ -222,7 +230,7 @@ const install = (app: App, opt: InstallOptions): void => { }) plugins.forEach(plugin => { - app.use(plugin as any) + app.use(plugin) }) } diff --git a/packages/infinite-scroll/index.ts b/packages/infinite-scroll/index.ts index 6ea4f1e1fc..237ab82c79 100644 --- a/packages/infinite-scroll/index.ts +++ b/packages/infinite-scroll/index.ts @@ -1,8 +1,10 @@ -import { App } from 'vue' import InfiniteScroll from './src/index' +import type { SFCWithInstall } from '@element-plus/utils/types' -(InfiniteScroll as any).install = (app: App): void => { - app.directive('InfiniteScroll', InfiniteScroll) +const _InfiniteScroll: SFCWithInstall = InfiniteScroll as SFCWithInstall + +_InfiniteScroll.install = app => { + app.directive('InfiniteScroll', _InfiniteScroll) } -export default InfiniteScroll +export default _InfiniteScroll diff --git a/packages/message-box/index.ts b/packages/message-box/index.ts index 8d6d36606e..2989a97522 100644 --- a/packages/message-box/index.ts +++ b/packages/message-box/index.ts @@ -1,12 +1,14 @@ -import { App } from 'vue' import MessageBox from './src/messageBox' +import type { SFCWithInstall } from '@element-plus/utils/types' -(MessageBox as any).install = (app: App): void => { - app.config.globalProperties.$msgbox = MessageBox - app.config.globalProperties.$messageBox = MessageBox - app.config.globalProperties.$alert = MessageBox.alert - app.config.globalProperties.$confirm = MessageBox.confirm - app.config.globalProperties.$prompt = MessageBox.prompt +const _MessageBox: SFCWithInstall = MessageBox as SFCWithInstall + +_MessageBox.install = app => { + app.config.globalProperties.$msgbox = _MessageBox + app.config.globalProperties.$messageBox = _MessageBox + app.config.globalProperties.$alert = _MessageBox.alert + app.config.globalProperties.$confirm = _MessageBox.confirm + app.config.globalProperties.$prompt = _MessageBox.prompt } -export default MessageBox +export default _MessageBox diff --git a/packages/message/index.ts b/packages/message/index.ts index 4756e4aee2..09ac8f3cc5 100644 --- a/packages/message/index.ts +++ b/packages/message/index.ts @@ -1,8 +1,10 @@ -import { App } from 'vue' import Message from './src/message' +import type { SFCWithInstall } from '@element-plus/utils/types' -(Message as any).install = (app: App): void => { - app.config.globalProperties.$message = Message +const _Message: SFCWithInstall = Message as SFCWithInstall + +_Message.install = app => { + app.config.globalProperties.$message = _Message } -export default Message +export default _Message diff --git a/packages/notification/index.ts b/packages/notification/index.ts index efcbe3c90f..433ef0d322 100644 --- a/packages/notification/index.ts +++ b/packages/notification/index.ts @@ -1,8 +1,10 @@ -import { App } from 'vue' import Notify from './src/notify' +import type { SFCWithInstall } from '@element-plus/utils/types' -(Notify as any).install = (app: App): void => { - app.config.globalProperties.$notify = Notify +const _Notify: SFCWithInstall = Notify as SFCWithInstall + +_Notify.install = app => { + app.config.globalProperties.$notify = _Notify } -export default Notify +export default _Notify diff --git a/packages/option/index.ts b/packages/option/index.ts index 4fd8463588..a52b197c91 100644 --- a/packages/option/index.ts +++ b/packages/option/index.ts @@ -1,8 +1,10 @@ -import { App } from 'vue' import { Option } from '@element-plus/select' +import type { SFCWithInstall } from '@element-plus/utils/types' -Option.install = (app: App): void => { - app.component(Option.name, Option) +const _Option: SFCWithInstall = Option as SFCWithInstall + +_Option.install = app => { + app.component(_Option.name, _Option) } -export default Option +export default _Option diff --git a/packages/pagination/index.ts b/packages/pagination/index.ts index 536d39a19d..077f9b99b3 100644 --- a/packages/pagination/index.ts +++ b/packages/pagination/index.ts @@ -1,9 +1,10 @@ -import { App } from 'vue' import Pagination from './src/index' +import type { SFCWithInstall } from '@element-plus/utils/types' -Pagination.install = (app: App): void => { - app.component(Pagination.name, Pagination) +const _Pagination: SFCWithInstall = Pagination as SFCWithInstall + +_Pagination.install = app => { + app.component(_Pagination.name, _Pagination) } -export default Pagination - +export default _Pagination diff --git a/packages/row/index.ts b/packages/row/index.ts index d7f4e0f525..dea73a0f19 100644 --- a/packages/row/index.ts +++ b/packages/row/index.ts @@ -1,8 +1,10 @@ -import { App } from 'vue' import Row from '../col/src/row' +import type { SFCWithInstall } from '@element-plus/utils/types' -Row.install = (app: App): void => { - app.component(Row.name, Row) +const _Row: SFCWithInstall = Row as SFCWithInstall + +_Row.install = app => { + app.component(_Row.name, _Row) } -export default Row +export default _Row diff --git a/packages/space/index.ts b/packages/space/index.ts index 3bec097bc0..dd94239f68 100644 --- a/packages/space/index.ts +++ b/packages/space/index.ts @@ -1,11 +1,10 @@ -import { App } from 'vue' import Space from './src/index' import type { SFCWithInstall } from '@element-plus/utils/types' -Space.install = (app: App): void => { - app.component(Space.name, Space) +const _Space: SFCWithInstall = Space as SFCWithInstall + +_Space.install = app => { + app.component(_Space.name, _Space) } -const _Space: SFCWithInstall = Space as any - export default _Space diff --git a/packages/table-column/index.ts b/packages/table-column/index.ts index c10125e23d..2f7dcefacc 100644 --- a/packages/table-column/index.ts +++ b/packages/table-column/index.ts @@ -1,8 +1,10 @@ -import { App } from 'vue' import TableColumn from '../table/src/tableColumn' +import type { SFCWithInstall } from '@element-plus/utils/types' -TableColumn.install = (app: App): void => { - app.component(TableColumn.name, TableColumn) +const _TableColumn: SFCWithInstall = TableColumn as SFCWithInstall + +_TableColumn.install = app => { + app.component(_TableColumn.name, _TableColumn) } -export default TableColumn +export default _TableColumn diff --git a/packages/time-picker/index.ts b/packages/time-picker/index.ts index 680fff2cf5..656880b67a 100644 --- a/packages/time-picker/index.ts +++ b/packages/time-picker/index.ts @@ -1,14 +1,16 @@ -import { App } from 'vue' import TimePicker from './src/time-picker' import CommonPicker from './src/common/picker.vue' import TimePickPanel from './src/time-picker-com/panel-time-pick.vue' +import type { SFCWithInstall } from '@element-plus/utils/types' export * from './src/common/date-utils' export * from './src/common/constant' export * from './src/common/props' -TimePicker.install = (app: App): void => { - app.component(TimePicker.name, TimePicker) +const _TimePicker: SFCWithInstall = TimePicker as SFCWithInstall + +_TimePicker.install = app => { + app.component(_TimePicker.name, _TimePicker) } export { CommonPicker, TimePickPanel } -export default TimePicker +export default _TimePicker diff --git a/packages/utils/types.ts b/packages/utils/types.ts index 1d2d35ba84..52078e7c0e 100644 --- a/packages/utils/types.ts +++ b/packages/utils/types.ts @@ -1,4 +1,4 @@ -import { App } from 'vue' +import type { App } from 'vue' type OptionalKeys> = { [K in keyof T]: T extends Record