codemix / babel-plugin-typecheck

Static and runtime type checking for JavaScript in the form of a Babel plugin.
MIT License
886 stars 44 forks source link

Spread operator + arrow function + typecheck on return = linting error #97

Closed planttheidea closed 8 years ago

planttheidea commented 8 years ago

Preface this by saying I am using babel (duh) with babel-eslint, and what I'm receiving is a linting error, however it appears to be specifically because of the flow types.

With this syntax:

const someFunc = (...args) : Array => {
   return args;
};

I receive an "Unexpected token" error, however with this syntax:

const someFunc = function(...args) : Array {
   return args;
};

No problem whatsoever. Pretty sure these should be interchangable, at least from the flow type perspective. I believe it is the typecheck because this is also successful:

const someFunc = (...args) => {
   return args;
};

I'm pretty sure I'm specifying the return type correctly (it works on all other declarations without the spread operator), its just specifically having issues with this spread operator.

phpnode commented 8 years ago

I don't believe this can be related to the plugin (but might be a bug in babel's parser). babel-eslint doesn't run any plugins because it doesn't do any transformations. It only runs the parser.

dchambers commented 8 years ago

Here's the corresponding Babel issue (not fixed at the time of writing):

For the time being you can work around this issue by wrapping the return type in a comment.