-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Fix flow nullable type definitions #868
Conversation
Flow uses parameter: ?type for nullable types (instead of parameter? :type as used before). I came across the warning when checking react-native (react-native/Libraries/CustomComponents/Navigator/Navigation/NavigationRouteStack.js:121) and slice was passed a nullable value which resulted in errors.
@leebyron sorry to ping you directly, it just has been a week and I figured it won't hurt ;) |
@TobiasBales, I've been using
unless there are other changes you want to still get merged, I would suggest closing the PR. |
begin and end which are passed to Array.prototype.slice are both nullable, which results in the error. I will gladly amend the commit to include both |
Nullable and optional mean different things. So it really depends on a case-by-case basis. That said, the example from the React-Native code looks wrong to me. Perhaps that's a place for a PR! As an another example let me explain what the difference is:
slice(begin: ?number, end: ?number): RouteStack {
var routeNodes = this._routeNodes.slice(begin, end);
var index = Math.min(this._index, routeNodes.size - 1);
return this._update(index, routeNodes);
}
///
slice(null, null) // legal
slice() // ERROR
slice(1, null) //legal
slice(undefined, 2) // legal
slice(2) //ERROR
slice(begin?: number, end?: number): RouteStack {
var routeNodes = this._routeNodes.slice(begin, end);
var index = Math.min(this._index, routeNodes.size - 1);
return this._update(index, routeNodes);
}
///
slice(null, null) // ERROR
slice() // legal
slice(1, null) //ERROR
slice(undefined, 2) // ERROR
slice(2) // legal Does that make sense? |
Yeah it does and I am aware of the distinction. My thought (after your comment) was, that slice(begin?: ?number, end?: ?number) would be the more flexible and correct (since slice does accept null values) solution. |
So #878 refactored the flow types and also added tests for them. Would you mind updating this PR to merge those changes in, and also add a test that catches this? Thanks! |
Closing this - the changed lines are all intentionally optional function arguments and are not nullable types. |
Flow uses parameter: ?type for nullable types (instead of parameter? :type as used before.
I came across the warning when checking react-native
(react-native/Libraries/CustomComponents/Navigator/Navigation/NavigationRouteStack.js:121)
and slice was passed a nullable value which resulted in errors.