jsx-control-statements icon indicating copy to clipboard operation
jsx-control-statements copied to clipboard

FlowType Support

Open AlexGilleran opened this issue 9 years ago • 8 comments

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 avatar Aug 23 '16 01:08 AlexGilleran

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

AlexGilleran avatar Aug 30 '16 11:08 AlexGilleran

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.

gajus avatar May 16 '17 13:05 gajus

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

apsavin avatar May 29 '17 14:05 apsavin

I'm open to suggestions :(.

AlexGilleran avatar May 29 '17 14:05 AlexGilleran

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

apsavin avatar May 29 '17 14:05 apsavin

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

gajus avatar Aug 23 '17 17:08 gajus

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 avatar Aug 23 '17 23:08 AlexGilleran

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

AlexGilleran avatar Aug 23 '17 23:08 AlexGilleran