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
F3373323: D9703.diff
Tue, Nov 26, 9:01 AM
Unknown Object (File)
Sun, Nov 24, 4:09 PM
Unknown Object (File)
Sat, Nov 23, 6:04 PM
Unknown Object (File)
Fri, Nov 22, 10:48 PM
Unknown Object (File)
Fri, Nov 22, 6:22 PM
Unknown Object (File)
Fri, Nov 8, 4:04 AM
Unknown Object (File)
Sun, Oct 27, 10:49 PM
Unknown Object (File)
Sun, Oct 27, 10:49 PM
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.