How to use SyntheticEvent in flow 0.132 and newer?

Viewed 106

Well I now decided to update past version 0.131.0 from flow. However this has the following breaking change:

Disallow using any-typed values type annotations.

(https://github.com/facebook/flow/releases/tag/v0.132.0)

This leads to a break with SyntheticEvent in the following context:

function requestRemove(ev: SyntheticEvent<HTMLElement>, extra_option: ExtraOptionSchema) {
    ev.stopPropagation();
    //more code
}

The error shown:

Error:(124, 41) Cannot use `SyntheticEvent` as a type because it is an `any`-typed value. Type `SyntheticEvent` properly, so it is no longer `any`-typed, to use it as an annotation.

If I remove the ev.stopPropagation() (and all other reference to the event such a ev.currentTarget) it works perfectly fine, no error is shown at all. (PS: the error is shown in 0.140.0 however manual testing shows it persist until I go back to version 0.131.0, which coincides with the changelog exempt above).

React is imported by:

import * as React from 'react';

And I've also tried to be more explicit by stating the type as: React.SyntheticEvent<HTMLElement> or SyntheticInputEvent<HTMLElement>. But this gave the error:

Error:(124, 47) Cannot get `React.SyntheticEvent` because property `SyntheticEvent` is missing in  module `react` [1].
0 Answers
Related