Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix generated flow type rule w readonly/aliased types #60

Merged

Conversation

Projects
None yet
4 participants
@josephsavona
Copy link
Contributor

commented Jun 3, 2019

Fixes a fatal where validateObjectTypeAnnotation() fatals when passed an unexpected value (when propType isn't an ObjectTypeAnnotation as expected). This can occur when GenericTypeAnnotations aren't filtered later in the file. The simple fix was to just filter out non-ObjectTypeAnnotation values, but I noticed this bug because of an example involving $ReadOnly<Props>. I realized we aren't unwrapping ReadOnly values, and also aren't fully resolving aliases, so I implemented support for those and then filtered out non-object types only afterwards.

.filter(maybeObjectType => {
// GenericTypeAnnotation may not map to an object type
return maybeObjectType &&
maybeObjectType.type === 'ObjectTypeAnnotation';

This comment has been minimized.

Copy link
@josephsavona

josephsavona Jun 3, 2019

Author Contributor

The lack of a filter here meant a non-ObjectTypeAnnotation could be passed below

}
// otherwise report an error at the first object
validateObjectTypeAnnotation(

This comment has been minimized.

Copy link
@josephsavona

josephsavona Jun 3, 2019

Author Contributor

...the invalid value would have passed here

if (lintResults.some(result => result)) {
// One of the intersected objects has it right
break;
for (const objectType of objectTypes) {

This comment has been minimized.

Copy link
@josephsavona

josephsavona Jun 3, 2019

Author Contributor

change to a loop to exit early once we know there's a valid type

errors: [
{
message:
'`user` is not declared in the `props` of the React component or it is not marked with the generated flow type `MyComponent_user`. ' +

This comment has been minimized.

Copy link
@mrtnzlml

mrtnzlml Jun 4, 2019

Hi @josephsavona! Could you please check this issue? #59 I think it's related to what you wrote here since seems like it doesn't work as expected (even though in this case it's probably fine).

This comment has been minimized.

Copy link
@josephsavona

josephsavona Jun 13, 2019

Author Contributor

That looks like a separate issue. The issue here is just that we’re not following type aliases and not unwrapping readonly. Happy to accept PRs for #59 though!

@kassens kassens merged commit a348ee4 into relayjs:master Jun 13, 2019

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.