Skip to content

Commit d581239

Browse files
whiteyebrwautofix-ci[bot]ilyaliaoantfu
authored
fix(onClickOutside): the order of overload signatures (#4839)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: IlyaL <ilyaliao324@gmail.com> Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
1 parent 5c2a1c7 commit d581239

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

packages/core/onClickOutside/index.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,19 @@ export interface OnClickOutsideOptions<Controls extends boolean = false> extends
3232
}
3333

3434
export type OnClickOutsideHandler<
35-
T extends {
36-
detectIframe: OnClickOutsideOptions['detectIframe']
37-
controls: boolean
38-
} = { detectIframe: false, controls: false },
35+
T extends OnClickOutsideOptions<boolean> = OnClickOutsideOptions,
3936
> = (
40-
event: T['controls'] extends true ? Event | (T['detectIframe'] extends true
41-
? PointerEvent | FocusEvent
42-
: PointerEvent) : T['detectIframe'] extends true
43-
? PointerEvent | FocusEvent
44-
: PointerEvent,
37+
event: (T['detectIframe'] extends true ? FocusEvent : never)
38+
| (T['controls'] extends true ? Event : never)
39+
| PointerEvent,
4540
) => void
4641

42+
interface OnClickOutsideControlsReturn {
43+
stop: Fn
44+
cancel: Fn
45+
trigger: (event: Event) => void
46+
}
47+
4748
let _iOSWorkaround = false
4849

4950
/**
@@ -54,17 +55,21 @@ let _iOSWorkaround = false
5455
* @param handler
5556
* @param options
5657
*/
57-
export function onClickOutside(
58+
export function onClickOutside<
59+
T extends OnClickOutsideOptions,
60+
>(
5861
target: MaybeElementRef,
59-
handler: OnClickOutsideHandler<{ detectIframe: OnClickOutsideOptions['detectIframe'], controls: true }>,
60-
options: OnClickOutsideOptions<true>,
61-
): { stop: Fn, cancel: Fn, trigger: (event: Event) => void }
62+
handler: OnClickOutsideHandler<T>,
63+
options?: T
64+
): Fn
6265

63-
export function onClickOutside(
66+
export function onClickOutside<
67+
T extends OnClickOutsideOptions<true>,
68+
>(
6469
target: MaybeElementRef,
65-
handler: OnClickOutsideHandler<{ detectIframe: OnClickOutsideOptions['detectIframe'], controls: false }>,
66-
options?: OnClickOutsideOptions<false>,
67-
): Fn
70+
handler: OnClickOutsideHandler<T>,
71+
options: T
72+
): OnClickOutsideControlsReturn
6873

6974
// Implementation
7075
export function onClickOutside(

0 commit comments

Comments
 (0)