Bargain23
Bargain23

Reputation: 1973

Flow - property missing in Event type

I have the following function:

createComment = (e: Event) => {
  if (e.key === 'Enter') {
    e.preventDefault()
    ...
  }
}

but Flow is returning this error Property key is missing in Event. How do I resolve this?

Upvotes: 1

Views: 788

Answers (2)

Hemadri Dasari
Hemadri Dasari

Reputation: 33994

You should use SyntheticKeyboardEvent instead of Event

So change

    createComment = (e: Event) => {
           if (e.key === 'Enter') {
               e.preventDefault()
               ...
            }
     }

To

     createComment = (e: SyntheticKeyboardEvent<HTMLButtonElement>) => {
          if (e.key === 'Enter') {
              e.preventDefault()
              ...
          }
     }

Upvotes: 1

Bargain23
Bargain23

Reputation: 1973

Apparently, I should use KeyboardEvent instead of Event.

Upvotes: 0

Related Questions