flow-js2-mode icon indicating copy to clipboard operation
flow-js2-mode copied to clipboard

Return type on arrow functions not working

Open strayer opened this issue 7 years ago • 2 comments

It seems like this code is not working properly:

function func1(n: number): boolean {
  if (n > 1) {
    return true;
  } else {
    return false;
  }
}

const func2 = (n: number): boolean => {
  if (n > 2) {
    return true;
  } else {
    return false;
  }
};

The reported error is missing ; before statement.

grafik

strayer avatar Apr 27 '18 13:04 strayer

Thanks for the report!

I think I've run into something similar when annotating function types in signatures and I wasn't able to fix it there. I'm afraid this might be similar but I'll have a look.

The way I approach this now is really hackish in that it "overrides" some of the internal js2 methods but at times there is no good extension point for that.

I would like to participate in the js2-mode project a bit more and refactor it such that modes like this have easier time extending the syntax.

Fuco1 avatar Apr 27 '18 15:04 Fuco1

Hey, thanks for looking into it! Too bad, arrow functions with return types are very common in our React Native projects :( I won't be able to help with this in code, sadly – while I know functional programming, emacs and elisp are still very new to me. If I can somehow help, please reach out to me!

strayer avatar Apr 29 '18 20:04 strayer