From 89c01de6f16f5e1ea09b770ec484bb768bdf3014 Mon Sep 17 00:00:00 2001 From: msidolphin Date: Tue, 27 Jul 2021 09:09:12 +0800 Subject: [PATCH] fix(notification): improve type definition and define closeAll function (#2705) fix #2696 --- packages/notification/src/notification.type.ts | 14 ++++++++++++-- packages/notification/src/notify.ts | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/notification/src/notification.type.ts b/packages/notification/src/notification.type.ts index 2e6ff4044f..8edcdbccab 100644 --- a/packages/notification/src/notification.type.ts +++ b/packages/notification/src/notification.type.ts @@ -2,11 +2,21 @@ import type { VNode } from 'vue' export type Position = 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' +export type NotificationType = 'success' | 'warning' | 'info' | 'error' | '' +export type TypedNotificationOptions = Omit | string + export interface INotificationHandle { close: () => void } -export type INotification = (options?: INotificationOptions) => INotificationHandle +export interface INotification { + (options?: INotificationOptions) : INotificationHandle + success?: (options: TypedNotificationOptions) => INotificationHandle + warning?: (options: TypedNotificationOptions) => INotificationHandle + error?: (options: TypedNotificationOptions) => INotificationHandle + info?: (options: TypedNotificationOptions) => INotificationHandle + closeAll: () => void +} export type INotificationOptions = { customClass?: string @@ -21,7 +31,7 @@ export type INotificationOptions = { offset?: number // defaults 0 position?: Position // default top-right showClose?: boolean - type?: 'success' | 'warning' | 'info' | 'error' | '' + type?: NotificationType title?: string } diff --git a/packages/notification/src/notify.ts b/packages/notification/src/notify.ts index dde8332dd5..a57b852fe6 100644 --- a/packages/notification/src/notify.ts +++ b/packages/notification/src/notify.ts @@ -142,4 +142,6 @@ export function closeAll(): void { } } +Notification.closeAll = closeAll + export default Notification