Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
[TS Migration] Migrate '[Remaining Group 2]' hook to TypeScript #32484
[TS Migration] Migrate '[Remaining Group 2]' hook to TypeScript #32484
Changes from all commits
54f298d
4b88248
44280d9
4ec450a
6c420d6
1e156cc
fc72803
7fbb054
ed9a26b
5c42c73
b620ee8
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Is this necessary? Wouldn't the above early return protect against
inputRef.current
being falsy?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.
It is necessary, when I remove it, there is an error saying it could be undefined. Do you think we should remove it from the if statement in that case?
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 think it's unnecessary to have both the early return and the optional chaining. I think we should do one or the other. From what I've seen, we favor the optional chaining, so I would remove the early returns, yeah.
The early returns are good for when it's good to avoid unnecessary processing like
InteractionManager.runAfterInteractions()
.In this case, maybe the early return is good to keep. If there is no
inputRef.current
, then skipping therunAfterInteractions()
sounds like a good thing to do.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.
Sorry, I said to do two different things there. Let's keep the early return and the optional chaining (since that throws an error). No changes necessary.
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.
@tgolen The optional chaining is necessary because
inputRef.current?.focus();
is insideInteractionManager.runAfterInteractions
which is asynchronous and when it executes the callback inside, we have no guarantee thatinputRef.current
is still defined so TS will complain.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.
Can you help me understand the purpose of this file and why it's necessary?
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.
Sure! So this function was not originally in the library, afaik it was added with a patch, and it was good enough when we used JS, but once migrated to TypeScript it wasn't good enough anymore. I tried a couple solutions and this is the only one I found that works fully, importing it directly from the file and augmenting the types. We discussed it in our TS team and this is what we agreed on. Hope that answers your question!
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.
OK, thanks! That's good context. Would you mind adding a code comment to this file which explains that?
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.
Sure thing, done!