-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
[Fiber] Use T | null
instead of ?T
types
#8978
Conversation
Flow maybe types accept both null and undefined. When the final parameter of a function accepts a maybe type, passing nothing (undefined) successfully typechecks, which can lead to bugs if the omission is accidental. Being forced to pass null is harder to screw up. Explicit null checks are also faster.
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.
Didn't verify but I trust you. Did you only change checks against fibers or also others? Tests all pass?
@@ -1175,7 +1169,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P, | |||
// If we're not already inside a batch, we need to flush any task work | |||
// that was created by the user-provided function. | |||
if (!isPerformingWork && !isBatchingUpdates) { | |||
performWork(TaskPriority); | |||
performWork(TaskPriority, null); |
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.
Nice that we caught 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.
I actually don't know why Flow didn't catch this before, because the type on performWork
was already Deadline | null
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.
@acdlite I found flow would catch this if Deadline
was declared in ReactFiberScheduler
.More details facebook/flow#3368
@spicyj Mainly the Fiber type but I fixed most of the other optional types I found, too, with exceptions for things like user-facing functions. Possible there are a few that I missed. |
This broke some stuff. At least |
Ah. Actually I think the validation we do is correct, but we have an internal component that doesn't validate the ref. Interesting. |
Flow maybe types accept both null and undefined. When the final parameter of a function accepts a maybe type, passing nothing (undefined) successfully typechecks, which can lead to bugs if the omission is accidental. Being forced to pass null is harder to screw up.
Explicit null checks are also faster.