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

josephsavona
Copy link
Contributor

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';
Copy link
Contributor Author

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(
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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`. ' +
Copy link

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).

Copy link
Contributor Author

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!

@kassens kassens merged commit a348ee4 into relayjs:master Jun 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants