-
Notifications
You must be signed in to change notification settings - Fork 25k
refactor(codegen): extract throwIfArgumentPropsAreNull function in error-utils #37252
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
Conversation
Base commit: d8ced6f |
| if (!argumentProps) { | ||
| throw new Error(`Unable to determine event arguments for "${name}"`); | ||
| throwIfArgumentPropsAreNull(argumentProps, name); | ||
| } else if (!bubblingType) { | ||
| throwIfBubblingTypeIsNull(bubblingType, name); | ||
| } else { |
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.
This can be simplified to just:
throwIfArgumentPropsAreNull(argumentProps, name);
throwIfBubblingTypeIsNull(bubblingType, name);
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.
I tried, but there is a Flow error in the returned object because Flow doesn't infer that argumentProps and bubblingType cannot be null.
Do you know a way to fix this?
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.
So, the goal is to remove the if-else as Dmitry suggested. 🤔
one way could be to:
- Define a type alias like
type ArgumentProps = $FlowFixMe - Have
throwIfArgumentPropsAreNullreturnArgumentProps(not nullable) - invoke it like
argumentProps = throwIfArgumentPropsAreNull(argumentProps, name);
A bit ugly, but it should do the trick.
Otherwise, we can actually suppress the warning with a // eslint-disable-next-line <name of the broken rule> as we are actually sure that the props can't be null now.
I'm okay with both approaches!
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.
I chose the first option. Even though I don't like having to make the code more complex for typing reasons, I think it's safer.
cipolleschi
left a comment
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.
Thank you for taking the time to work on this changes. I left a comment to help solving the situation!
|
Thank you for working on this and to solve the issue. Do you have time to also rebase and fix the conflicts, please? 🙏 |
5cd2cd7 to
5450045
Compare
Done! |
|
/rebase |
5450045 to
0b9cf6e
Compare
|
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
@cipolleschi merged this pull request in f05252a. |
Summary:
This PR contains task 117 from #34872:
Changelog:
[Internal] [Changed] - Extract throwIfArgumentPropsAreNull function in error-utils
Test Plan:
I tested using Jest and Flow commands.