-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
fix(onClickOutside): the order of overload signatures #4839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
export function onClickOutside( | ||
target: MaybeElementRef, | ||
handler: OnClickOutsideHandler<{ detectIframe: OnClickOutsideOptions['detectIframe'], controls: true }>, | ||
options: OnClickOutsideOptions<true>, | ||
): { stop: Fn, cancel: Fn, trigger: (event: Event) => void } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you be able to assist with solving this kind of type inference issue as well? I’d really appreciate it!
onClickOutside(document.documentElement, (e) => {
// Currently, the type of e is `Event | PointerEvent`
// The correct type should be `Event | PointerEvent | FocusEvent`.
}, {
controls: true,
detectIframe: true
})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. i'll see what i can do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to add stricter overloads for the handler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we change it like this?
-export interface OnClickOutsideOptions<Controls extends boolean = false> extends ConfigurableWindow {
+export interface OnClickOutsideOptions<Controls extends boolean = false, DetectIframe extends boolean = false> extends ConfigurableWindow {
// ...
- detectIframe?: boolean
+ detectIframe?: DetectIframe
// ...
}
i think you could simplify this to two overloads 👀 you only need to know what so we could instead do something like this: export function onClickOutside<
T extends OnClickOutsideOptions<true>
>(
target: MaybeElementRef,
handler: OnClickOutsideHandler<T>,
options: T
): Controls;
export function onClickOutside<
T extends OnClickOutsideOptions<false>
>(
target: MaybeElementRef,
handler: OnClickOutsideHandler<T>,
options: T
): Fn; and export type OnClickOutsideHandler<
TControls extends boolean, // may not be needed? may be able to just do `<boolean>` below
T extends OnClickOutsideOptions<TControls>
> = (
event: (T['detectIframe'] extends true ? FocusEvent : never)
| (T['controls'] extends true ? Event : never)
| PointerEvent,
) => void |
Before submitting the PR, please make sure you do the following
fixes #123
).Description
Fixes #4838.
The order of Overload Signatures has been changed.
Additional context