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
UnitControl component: Refactor utils to TypeScript #35138
UnitControl component: Refactor utils to TypeScript #35138
Changes from all commits
f21349c
c4f129a
11e7f22
fa9fe44
8d4976a
224d868
b7030b3
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.
We should consider this change carefully, since it introduces a runtime change —
isNaN
doesn't always return the same results as! Number.isFinite
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.
Thanks for pointing this out, I meant to leave a specific comment for it. With the switch to TypeScript, using
isNaN
here generated an error:This seems to be that in TS,
isNaN
expects to be called with a variable of typenumber
, but ourparsedValue
is either a number or a string. At this point ingetValidParsedUnit
theparsedValue
variable must be either a number or an empty string (the results of callingparseUnit
). So, I thinkNumber.isFinite
is a more appropriate check thanisNaN
anyway, at least from my mental model of what this function should be doing:NaN
Infinity
or-Infinity
) and not an arbitrary stringIf it doesn't meet the above criteria then we fall back to the
fallbackValue
. One difference in usingNumber.isFinite
is that the value won't be coerced to a number before checking to see if it's finite. I think this is okay, because the value has already been coerced inparseUnit
so at this point it should be a real (finite) value in order for us to consider it valid.Please let me know if you think that's not right, though! Happy to change the logic here, I think it's the main place where I had to introduce a runtime change, but 🤞 it isn't an unexpected one in usage.
It could be that we might want to tighten up the Value type a bit further, too, given that in some places it'll only be
number
or the string literal''
— I was a bit cautious about doing that, as we'd then have two different Value types floating around in the file, which could get confusing? But it also might make it a bit clearer 🤔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 the explanation! With this context (and the extra reassurance given by the passing unit tests), I think we can leave your new implementation untouched.
I would maybe only add a comment with a short version of the explanation you just gave in your previous message.
I had the same thought and came to the same conclusion