Skip to content

Commit 38ef933

Browse files
committed
enhance type
1 parent 1682a86 commit 38ef933

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

plugins/dialog/guest-js/index.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ export type MessageDialogDefaultButtons =
8888
| 'YesNo'
8989
| 'YesNoCancel'
9090

91+
/** All possible button keys. */
92+
type ButtonKey = 'ok' | 'cancel' | 'yes' | 'no'
93+
94+
/** Ban everything except a set of keys. */
95+
type BanExcept<Allowed extends ButtonKey> = Partial<
96+
Record<Exclude<ButtonKey, Allowed>, never>
97+
>
98+
9199
/**
92100
* The Yes, No and Cancel buttons of a message dialog.
93101
*
@@ -100,7 +108,7 @@ export type MessageDialogButtonsYesNoCancel = {
100108
no: string
101109
/** The Cancel button. */
102110
cancel: string
103-
}
111+
} & BanExcept<'yes' | 'no' | 'cancel'>
104112

105113
/**
106114
* The Ok and Cancel buttons of a message dialog.
@@ -112,7 +120,7 @@ export type MessageDialogButtonsOkCancel = {
112120
ok: string
113121
/** The Cancel button. */
114122
cancel: string
115-
}
123+
} & BanExcept<'ok' | 'cancel'>
116124

117125
/**
118126
* The Ok button of a message dialog.
@@ -122,7 +130,7 @@ export type MessageDialogButtonsOkCancel = {
122130
export type MessageDialogButtonsOk = {
123131
/** The Ok button. */
124132
ok: string
125-
}
133+
} & BanExcept<'ok'>
126134

127135
/**
128136
* Custom buttons for a message dialog.

0 commit comments

Comments
 (0)