0
votes

I recently updated a project using Flow to version 0.138.0. After the update, it's the first time I'm stumbling upon similar errors like this:

Cannot build a typed interface for this module. You should annotate the exports of this module with types. Missing type annotation at property _dispatchUpdate: [signature-verification-failure]

Our project consists of many classes and some of them will look like this

export class SomeActions {
  _interval: IntervalID;
  _isPolling: boolean;

  _dispatchUpdate = (downloadItems: DownloadItems[]): void => {
     AppDispatcher.dispatch({
       actionType: CONSTANT.CONSTANT,
       downloadItems,
     })
  }
} 

export default new SomeActions();

In order to solve the error in question, I began implementing an interface like the following

interface SomeActionsT {
  _interval: IntervalID;
  _ isPolling: boolean;
  
  _dispatchUpdate: (DownloadItems[]): void;
}

export class SomeActions implements SomeActionsT {
  _interval: IntervalID;
  _isPolling: boolean;

  _dispatchUpdate = (downloadItems: DownloadItems[]): void => {
     AppDispatcher.dispatch({
       actionType: CONSTANT.CONSTANT,
       downloadItems,
     })
  }
} 

export default new SomeActions();

But the flow error still exists. If I refactor the _dispatchUpdate to being a normal function, it will not complain anymore. But that's silly. How can I go about making flow recognize the arrow function?

1

1 Answers

0
votes

Firstly you're getting these errors probably because you updated from an old version that didn't have types-first on by default. Explained here.

To solve your issue you can type your class like so

export class SomeActions {
  _interval: IntervalID;

  _isPolling: boolean;

  _dispatchUpdate: DownloadItems[] => void = (downloadItems) => {
    AppDispatcher.dispatch({
      actionType: CONSTANT.CONSTANT,
      downloadItems,
    });
  }
}

export default (new SomeActions(): SomeActions);

Because you're exporting new Class you have to declare the type of that also explicitly, otherwise just export default SomeActions; is sufficient.