-
Notifications
You must be signed in to change notification settings - Fork 47
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
Fix generated flow type rule w readonly/aliased types #60
Conversation
src/rule-generated-flow-types.js
Outdated
.filter(maybeObjectType => { | ||
// GenericTypeAnnotation may not map to an object type | ||
return maybeObjectType && | ||
maybeObjectType.type === 'ObjectTypeAnnotation'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lack of a filter here meant a non-ObjectTypeAnnotation could be passed below
} | ||
// otherwise report an error at the first object | ||
validateObjectTypeAnnotation( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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`. ' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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!
Fixes a fatal where
validateObjectTypeAnnotation()
fatals when passed an unexpected value (whenpropType
isn't anObjectTypeAnnotation
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.