-
Notifications
You must be signed in to change notification settings - Fork 84
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
Question about VoidableEventCallback #60
Comments
It's seem like a const [callback, flag] = useEventCallback(($events: Observable<React.MouseEvent<HTMLElement> | boolean>) => $events.pipe(mapTo(false)), false)
callback(true) |
Same result. It's the |
What's version of the TypeScript in your project? |
I'm using 3.5.2 too.
Found this on the doc, might be the reason?
|
It's a known trick of Typescript, that is when a union is put in a contravariant place(like function parameter) in conditional type it will be turned into a intersection type. So There is one easy and tricky solution type VoidableEventCallback<EventValue> = {
0: () => void
1: (e: EventValue) => void
}[EventValue extends void ? 0 : 1] But @Brooooooklyn what is the purpose of this type in the first place? In Typescript a function with a void parameter is quite identical to a function with no parameter declare function foo(a: void): void
foo()
foo(1) // error |
Very insightful! Didn't know a trick like this. Wish you'd comment earlier so that I don't have to make my own wheels. |
I was trying write something like
And there was type error.
Checking the source
rxjs-hooks/src/use-event-callback.ts
Line 6 in 2b781f1
It seems like for example
will be resolved as
which means
e
has to bestring & boolean
. Is this a bug or am I missing something here?The text was updated successfully, but these errors were encountered: