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

[Fiber] Use T | null instead of ?T types #8978

Merged
merged 1 commit into from
Feb 13, 2017

Conversation

acdlite
Copy link
Collaborator

@acdlite acdlite commented Feb 11, 2017

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.

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.
Copy link
Collaborator

@sophiebits sophiebits left a 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);
Copy link
Collaborator

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.

Copy link
Collaborator Author

@acdlite acdlite Feb 11, 2017

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

Copy link
Contributor

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

@acdlite
Copy link
Collaborator Author

acdlite commented Feb 11, 2017

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

@acdlite acdlite merged commit 6621706 into facebook:master Feb 13, 2017
@sebmarkbage
Copy link
Collaborator

sebmarkbage commented Feb 16, 2017

This broke some stuff. At least fiber.ref can be undefined. There might be more of those poorly typed cases where we can get invalid types in the system.

@sebmarkbage
Copy link
Collaborator

Ah. Actually I think the validation we do is correct, but we have an internal component that doesn't validate the ref. Interesting.

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.

6 participants