Page MenuHomePhabricator

[Flow202][lib][skip-ci] [11/23] Fix Flow issues with referencing this in object methods
ClosedPublic

Authored by ashoat on Nov 4 2023, 12:01 PM.
Tags
None
Referenced Files
F1743588: D9703.id33800.diff
Mon, May 13, 6:41 AM
Unknown Object (File)
Tue, May 7, 10:21 AM
Unknown Object (File)
Wed, May 1, 10:30 PM
Unknown Object (File)
Tue, Apr 16, 7:55 AM
Unknown Object (File)
Tue, Apr 16, 3:20 AM
Unknown Object (File)
Mon, Apr 15, 9:15 PM
Unknown Object (File)
Sun, Apr 14, 9:52 PM
Unknown Object (File)
Sun, Apr 14, 7:58 AM
Subscribers

Details

Summary

The new version of Flow is showing a bunch of errors that look like this:

Error ---------------------------------------------------------------- shared/messages/add-members-message-spec.js:45:12

Cannot reference this from within method messageContentForClientDB [1]. For safety, Flow restricts access to this inside
object methods since these methods may be unbound and rebound. Consider replacing the reference to this with the name of
the object, or rewriting the object as a class. [object-this-reference]

     42|   },
     43|
 [1] 44|   messageContentForClientDB(data: RawAddMembersMessageInfo): string {
     45|     return this.messageContentForServerDB(data);
     46|   },
     47|
     48|   rawMessageInfoFromServerDBRow(row: Object): RawAddMembersMessageInfo {

This diff addresses them by "replacing the reference to this with the name of the object" as suggested. That change initially introduced another type issue since messageContentForServerDB is optional in MessageSpec, so I had to also explicitly type each MessageSpec so that messageContentForServerDB is non-optional.

NOTE: CI will fail on this diff. I considered the possibility of fixing Flow errors BEFORE upgrading Flow, but it wasn't possible... in some cases, the fixes to support the new version of Flow caused errors in the old version. I could have hidden these type errors with $FlowFixMe lines and then later revert those, but that seemed like too much busy work.

Depends on D9702

Test Plan

Confirm the Flow errors go away

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Harbormaster returned this revision to the author for changes because remote builds failed.Nov 4 2023, 12:23 PM
Harbormaster failed remote builds in B23745: Diff 32707!
tomek added inline comments.
lib/shared/messages/add-members-message-spec.js
43 ↗(On Diff #32707)

Doesn't matter too much, but can this type be exact?

This revision is now accepted and ready to land.Nov 6 2023, 4:48 AM
ashoat retitled this revision from [Flow202][lib] [11/23] Fix Flow issues with referencing this in object methods to [Flow202][lib][skip-ci] [11/23] Fix Flow issues with referencing this in object methods.Nov 19 2023, 11:47 AM
This revision was landed with ongoing or failed builds.Nov 27 2023, 3:25 PM
This revision was automatically updated to reflect the committed changes.