AlexGilleran / jsx-control-statements

Neater If and For for React JSX
https://www.npmjs.com/package/babel-plugin-jsx-control-statements
MIT License
1.62k stars 64 forks source link

FlowType Support #51

Open AlexGilleran opened 8 years ago

AlexGilleran commented 8 years ago

Just making this to keep track of it, I don't have a complete solution at this stage.

FlowType doesn't like JSX-Control-Statements in two ways - the first is that we're effectively using global types which is easily fixed with a type declaration:

// @flow

type ForType = ReactClass<{each: string, index: string, of: any}>;

declare var For: ForType;

But the problem is the "each" and "index" of the For won't be known to FlowType and it'll not only fail, but also not support type checking which sucks.

Best I have so far is to just declare those variables in the render function with the right type.

AlexGilleran commented 8 years ago

Have added flow types to the build, which fixes like 2/3 of this but doesn't quite get us all the way :(.

gajus commented 7 years ago

Without Flowtype support, jsx-control-statements is useless in a project that uses Flowtype, e.g.

<If condition={movie}>
  <div>{movie.name}</div>
</If>

(where movie can null) movie.name will always trigger Flow error.

I am not sure if it possible to solve this in Flowtype.

apsavin commented 7 years ago

@AlexGilleran Can we do something to teach flow what If control statement does?

AlexGilleran commented 7 years ago

I'm open to suggestions :(.

apsavin commented 7 years ago

I opened an issue with a question in flow repo: https://github.com/facebook/flow/issues/4057

gajus commented 7 years ago

@AlexGilleran @apsavin Has there been any progress on this?

AlexGilleran commented 7 years ago

Not in a way that helps us:

Flow understands javascript and jsx semantics. This plugin changes it, so the code is not compatible with flow anymore

Which is fair enough, but also :(.

AlexGilleran commented 7 years ago

Although maybe https://github.com/facebook/flow/issues/1515 can save us eventually.