-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
[createReactClass, TimerMixin] remove createReactClass and TImerMixin from TimerTest.js #21748
Conversation
_interval = -1; | ||
_timeoutID: ?TimeoutID = null; | ||
// $FlowFixMe | ||
_intervalId: ?IntervalID = -1; |
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.
// $FlowFixMe
_intervalId: ?IntervalID = -1;
I've had issues with Flow here and on the contructor.displayName
because null or undefined is
incompatible with IntervalID,
and number is incompatible with IntervalID
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 commented below how we can fix this.
{/* $FlowFixMe(>=0.54.0 site=react_native_fb,react_native_oss) This | ||
* comment suppresses an error found when Flow v0.54 was deployed. | ||
* To see the error delete this comment and run Flow. */ | ||
this.constructor.displayName + ': \n'} |
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.
IIRC, the displayName is added on to our components in a babel transform. Flow doesn't know anything about that, so that's probably why it's raising this error.
I think there're three fixes:
- Change
this.constructor.displayName
tothis.constructor.name
. (Both should be equivalent). - Redundantly define the
displayName
static property in this class. - Hardcode 'TimerTest' instead of
this.constructor.displayName
.
Your call. 😄
|
||
_incrementInterval() { | ||
if (this.state.count > 3) { | ||
throw new Error('interval incremented past end.'); | ||
} | ||
if (this.state.count === 3) { | ||
this.clearInterval(this._interval); | ||
clearInterval(this._intervalId); |
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.
The signature of clearInterval
is this:
function clearInterval(interval?: IntervalID) {
So clearInterval
expects an argument that is either an IntervalID
, undefined
, or not present at all. You're passing in a value that's ?IntervalID
, which is equivalent to IntervalID
, undefined
, or null
. (The bottom line is that clearInterval
does not accept null
as an argument). Therefore, If you guard this function call with a null check, your flow error should go away.
if (this.state.count === 3) {
if (this._intervalId != null) {
clearInterval(this._intervalId);
}
}
_interval = -1; | ||
_timeoutID: ?TimeoutID = null; | ||
// $FlowFixMe | ||
_intervalId: ?IntervalID = -1; |
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 commented below how we can fix this.
@@ -11,98 +11,106 @@ | |||
'use strict'; | |||
|
|||
const React = require('react'); | |||
const createReactClass = require('create-react-class'); | |||
const ReactNative = require('react-native'); | |||
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error |
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.
Let's get rid of all $FlowFixMe
s in this file.
}, | ||
}); | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { |
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.
Let's get rid of:
TimersTest.displayName = 'TimersTest';
If we want to define static properties on TimerTest
, we should do it using the static
keyword inside the TimerTest
class. That way, flow will be able to analyze the static property.
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.
RSNara has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
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.
Actually, I had some spare time, so I just took care of these changes. 😁
Thanks again @RSNara |
) Summary: Related to facebook#21485 (comment) Remove createReactClass and TimerMixin from IntegrationTests/TimersTest.js Pull Request resolved: facebook#21748 Reviewed By: TheSavior Differential Revision: D10366418 Pulled By: RSNara fbshipit-source-id: f7e9a1b62a17cd23374997f99dbfe239172b614f
Related to #21485 (comment)
Remove createReactClass and TimerMixin from IntegrationTests/TimersTest.js
Test Plan:
Flow tests succeed
Release Notes:
[GENERAL] [ENHANCEMENT] [IntegrationTests/TimersTest.js] Remove createReactClass and TimerMixin