Skip to content

Question about VoidableEventCallback #60

@crimx

Description

@crimx

I was trying write something like

const [callback, flag] = useEventCallback<
  React.MouseEvent<HTMLElement> | boolean,
  boolean
>($events => $events.pipe(mapTo(false)), false)

callback(true)

And there was type error.

Argument of type 'true' is not assignable to parameter of type 'false & true & MouseEvent<HTMLElement, MouseEvent>'.
  Type 'true' is not assignable to type 'false'.ts(2345)

Checking the source

export type VoidableEventCallback<EventValue> = EventValue extends void ? () => void : (e: EventValue) => void

It seems like for example

type Callback = VoidableEventCallback<string | boolean>

will be resolved as

type Callback = ((e: string) => void) | ((e: false) => void) | ((e: true) => void)

which means e has to be string & boolean. Is this a bug or am I missing something here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions