Skip to content

Commit e6868d8

Browse files
committedJan 11, 2019
actions: Clarify to Flow that these constants are type-tags.
When Flow sees a definition like `const FOO = 'FOO'`, it knows for some purposes that `FOO` is specifically `'FOO'`... but for others, it apparently broadens it to `string`. This is facebook/flow#2639. One consequence is that when we say switch (action.type) { case NOT_FOO_LOL: // ... use `action` ... break; // ... } with a `case` statement for a value of `type` that we've claimed is *impossible*... Flow quietly just decides that `action` has type `empty` and there's nothing to worry about. Then if our code goes and passes that `action` value to *any function at all*, Flow considers it valid. After all, there are no values of type `empty` (that's what `empty` is all about)... so it's true that every value of type `empty` is a valid value of whatever type it is that the function expected. So, that's pretty unfortunate. Fortunately, there is a workaround that causes Flow to behave better here: duplicate the value into the type, like `const FOO: 'FOO' = 'FOO'`. (This trick due to @geraldyeo and @fagerbua, in comments on facebook/flow#2377 -- thanks!) Do that, then. --- Made the edit with perl -i -0pe \ 's/export const ([A-Z_]+)\K =/: "$1" =/g' \ src/actionConstants.js and then manual fixup on the one exceptional case `REHYDRATE`, which Flow kindly pointed out. We had a whole bunch of type errors of the kind this hides; the bulk of them were for Event*Action types, and their fixes went into the parent commit. This commit adds one more missing action type which a number of reducers had type errors on, and a few other simple fixes. PS: A quick tip for reading this diff: `git log -p --patience`.
1 parent ea2b119 commit e6868d8

File tree

5 files changed

+94
-85
lines changed

5 files changed

+94
-85
lines changed
 

‎src/actionConstants.js

+90-84
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,98 @@
11
/* @flow strict */
2-
export const REHYDRATE = 'persist/REHYDRATE';
3-
4-
export const APP_ONLINE = 'APP_ONLINE';
5-
export const APP_ORIENTATION = 'APP_ORIENTATION';
6-
export const APP_STATE = 'APP_STATE';
7-
export const DEAD_QUEUE = 'DEAD_QUEUE';
8-
9-
export const REALM_ADD = 'REALM_ADD';
10-
export const ACCOUNT_ADD_SUCCEEDED = 'ACCOUNT_ADD_SUCCEEDED';
11-
export const ACCOUNT_REMOVE = 'ACCOUNT_REMOVE';
12-
export const ACCOUNT_SWITCH = 'ACCOUNT_SWITCH';
13-
14-
export const LOGIN_SUCCESS = 'LOGIN_SUCCESS';
15-
export const HTTP_UNAUTHORIZED = 'HTTP_UNAUTHORIZED';
16-
export const LOGOUT = 'LOGOUT';
17-
18-
export const REALM_INIT = 'REALM_INIT';
19-
export const DO_NARROW = 'DO_NARROW';
20-
21-
export const INIT_SAFE_AREA_INSETS = 'INIT_SAFE_AREA_INSETS';
22-
export const INITIAL_FETCH_START = 'INITIAL_FETCH_START';
23-
export const INITIAL_FETCH_COMPLETE = 'INITIAL_FETCH_COMPLETE';
24-
export const INIT_STREAMS = 'INIT_STREAMS';
25-
export const INIT_SUBSCRIPTIONS = 'INIT_SUBSCRIPTIONS';
26-
export const INIT_REALM_EMOJI = 'INIT_REALM_EMOJI';
27-
export const INIT_REALM_FILTER = 'INIT_REALM_FILTER';
28-
export const INIT_TOPICS = 'INIT_TOPICS';
29-
30-
export const EVENT_NEW_MESSAGE = 'EVENT_NEW_MESSAGE';
31-
export const EVENT_MESSAGE_DELETE = 'EVENT_MESSAGE_DELETE';
32-
export const EVENT_STREAM_ADD = 'EVENT_STREAM_ADD';
33-
export const EVENT_STREAM_REMOVE = 'EVENT_STREAM_REMOVE';
34-
export const EVENT_STREAM_UPDATE = 'EVENT_STREAM_UPDATE';
35-
export const EVENT_STREAM_OCCUPY = 'EVENT_STREAM_OCCUPY';
36-
export const EVENT_SUBSCRIPTION_ADD = 'EVENT_SUBSCRIPTION_ADD';
37-
export const EVENT_SUBSCRIPTION_REMOVE = 'EVENT_SUBSCRIPTION_REMOVE';
38-
export const EVENT_SUBSCRIPTION_UPDATE = 'EVENT_SUBSCRIPTION_UPDATE';
39-
export const EVENT_SUBSCRIPTION_PEER_ADD = 'EVENT_SUBSCRIPTION_PEER_ADD';
40-
export const EVENT_SUBSCRIPTION_PEER_REMOVE = 'EVENT_SUBSCRIPTION_PEER_REMOVE';
41-
export const EVENT_UPDATE_MESSAGE = 'EVENT_UPDATE_MESSAGE';
42-
export const EVENT_REACTION_ADD = 'EVENT_REACTION_ADD';
43-
export const EVENT_REACTION_REMOVE = 'EVENT_REACTION_REMOVE';
44-
export const EVENT_PRESENCE = 'EVENT_PRESENCE';
45-
export const EVENT_TYPING_START = 'EVENT_TYPING_START';
46-
export const EVENT_TYPING_STOP = 'EVENT_TYPING_STOP';
47-
export const EVENT_UPDATE_MESSAGE_FLAGS = 'EVENT_UPDATE_MESSAGE_FLAGS';
48-
export const EVENT_USER_ADD = 'EVENT_USER_ADD';
49-
export const EVENT_USER_REMOVE = 'EVENT_USER_REMOVE';
50-
export const EVENT_USER_UPDATE = 'EVENT_USER_UPDATE';
51-
export const EVENT_MUTED_TOPICS = 'EVENT_MUTED_TOPICS';
52-
53-
export const EVENT_USER_GROUP_ADD = 'EVENT_USER_GROUP_ADD';
54-
export const EVENT_USER_GROUP_REMOVE = 'EVENT_USER_GROUP_REMOVE';
55-
export const EVENT_USER_GROUP_UPDATE = 'EVENT_USER_GROUP_UPDATE';
56-
export const EVENT_USER_GROUP_ADD_MEMBERS = 'EVENT_USER_GROUP_ADD_MEMBERS';
57-
export const EVENT_USER_GROUP_REMOVE_MEMBERS = 'EVENT_USER_GROUP_REMOVE_MEMBERS';
58-
59-
export const MESSAGE_FETCH_START = 'MESSAGE_FETCH_START';
60-
export const MESSAGE_FETCH_COMPLETE = 'MESSAGE_FETCH_COMPLETE';
61-
62-
export const PRESENCE_RESPONSE = 'PRESENCE_RESPONSE';
63-
export const GET_USER_RESPONSE = 'GET_USER_RESPONSE';
64-
export const MARK_MESSAGES_READ = 'MARK_MESSAGES_READ';
65-
export const SETTINGS_CHANGE = 'SETTINGS_CHANGE';
66-
export const DEBUG_FLAG_TOGGLE = 'DEBUG_FLAG_TOGGLE';
67-
68-
export const GOT_PUSH_TOKEN = 'GOT_PUSH_TOKEN';
69-
export const ACK_PUSH_TOKEN = 'ACK_PUSH_TOKEN';
70-
export const UNACK_PUSH_TOKEN = 'UNACK_PUSH_TOKEN';
71-
72-
export const EVENT_REALM_EMOJI_UPDATE = 'EVENT_REALM_EMOJI_UPDATE';
73-
export const EVENT_REALM_FILTERS = 'EVENT_REALM_FILTERS';
74-
75-
export const EVENT_UPDATE_DISPLAY_SETTINGS = 'EVENT_UPDATE_DISPLAY_SETTINGS';
76-
export const EVENT_UPDATE_GLOBAL_NOTIFICATIONS_SETTINGS =
2+
export const REHYDRATE: 'persist/REHYDRATE' = 'persist/REHYDRATE';
3+
4+
export const APP_ONLINE: 'APP_ONLINE' = 'APP_ONLINE';
5+
export const APP_ORIENTATION: 'APP_ORIENTATION' = 'APP_ORIENTATION';
6+
export const APP_STATE: 'APP_STATE' = 'APP_STATE';
7+
export const DEAD_QUEUE: 'DEAD_QUEUE' = 'DEAD_QUEUE';
8+
9+
export const REALM_ADD: 'REALM_ADD' = 'REALM_ADD';
10+
export const ACCOUNT_ADD_SUCCEEDED: 'ACCOUNT_ADD_SUCCEEDED' = 'ACCOUNT_ADD_SUCCEEDED';
11+
export const ACCOUNT_REMOVE: 'ACCOUNT_REMOVE' = 'ACCOUNT_REMOVE';
12+
export const ACCOUNT_SWITCH: 'ACCOUNT_SWITCH' = 'ACCOUNT_SWITCH';
13+
14+
export const LOGIN_SUCCESS: 'LOGIN_SUCCESS' = 'LOGIN_SUCCESS';
15+
export const HTTP_UNAUTHORIZED: 'HTTP_UNAUTHORIZED' = 'HTTP_UNAUTHORIZED';
16+
export const LOGOUT: 'LOGOUT' = 'LOGOUT';
17+
18+
export const REALM_INIT: 'REALM_INIT' = 'REALM_INIT';
19+
export const DO_NARROW: 'DO_NARROW' = 'DO_NARROW';
20+
21+
export const INIT_SAFE_AREA_INSETS: 'INIT_SAFE_AREA_INSETS' = 'INIT_SAFE_AREA_INSETS';
22+
export const INITIAL_FETCH_START: 'INITIAL_FETCH_START' = 'INITIAL_FETCH_START';
23+
export const INITIAL_FETCH_COMPLETE: 'INITIAL_FETCH_COMPLETE' = 'INITIAL_FETCH_COMPLETE';
24+
export const INIT_STREAMS: 'INIT_STREAMS' = 'INIT_STREAMS';
25+
export const INIT_SUBSCRIPTIONS: 'INIT_SUBSCRIPTIONS' = 'INIT_SUBSCRIPTIONS';
26+
export const INIT_REALM_EMOJI: 'INIT_REALM_EMOJI' = 'INIT_REALM_EMOJI';
27+
export const INIT_REALM_FILTER: 'INIT_REALM_FILTER' = 'INIT_REALM_FILTER';
28+
export const INIT_TOPICS: 'INIT_TOPICS' = 'INIT_TOPICS';
29+
30+
export const EVENT_NEW_MESSAGE: 'EVENT_NEW_MESSAGE' = 'EVENT_NEW_MESSAGE';
31+
export const EVENT_MESSAGE_DELETE: 'EVENT_MESSAGE_DELETE' = 'EVENT_MESSAGE_DELETE';
32+
export const EVENT_STREAM_ADD: 'EVENT_STREAM_ADD' = 'EVENT_STREAM_ADD';
33+
export const EVENT_STREAM_REMOVE: 'EVENT_STREAM_REMOVE' = 'EVENT_STREAM_REMOVE';
34+
export const EVENT_STREAM_UPDATE: 'EVENT_STREAM_UPDATE' = 'EVENT_STREAM_UPDATE';
35+
export const EVENT_STREAM_OCCUPY: 'EVENT_STREAM_OCCUPY' = 'EVENT_STREAM_OCCUPY';
36+
export const EVENT_SUBSCRIPTION_ADD: 'EVENT_SUBSCRIPTION_ADD' = 'EVENT_SUBSCRIPTION_ADD';
37+
export const EVENT_SUBSCRIPTION_REMOVE: 'EVENT_SUBSCRIPTION_REMOVE' = 'EVENT_SUBSCRIPTION_REMOVE';
38+
export const EVENT_SUBSCRIPTION_UPDATE: 'EVENT_SUBSCRIPTION_UPDATE' = 'EVENT_SUBSCRIPTION_UPDATE';
39+
export const EVENT_SUBSCRIPTION_PEER_ADD: 'EVENT_SUBSCRIPTION_PEER_ADD' =
40+
'EVENT_SUBSCRIPTION_PEER_ADD';
41+
export const EVENT_SUBSCRIPTION_PEER_REMOVE: 'EVENT_SUBSCRIPTION_PEER_REMOVE' =
42+
'EVENT_SUBSCRIPTION_PEER_REMOVE';
43+
export const EVENT_UPDATE_MESSAGE: 'EVENT_UPDATE_MESSAGE' = 'EVENT_UPDATE_MESSAGE';
44+
export const EVENT_REACTION_ADD: 'EVENT_REACTION_ADD' = 'EVENT_REACTION_ADD';
45+
export const EVENT_REACTION_REMOVE: 'EVENT_REACTION_REMOVE' = 'EVENT_REACTION_REMOVE';
46+
export const EVENT_PRESENCE: 'EVENT_PRESENCE' = 'EVENT_PRESENCE';
47+
export const EVENT_TYPING_START: 'EVENT_TYPING_START' = 'EVENT_TYPING_START';
48+
export const EVENT_TYPING_STOP: 'EVENT_TYPING_STOP' = 'EVENT_TYPING_STOP';
49+
export const EVENT_UPDATE_MESSAGE_FLAGS: 'EVENT_UPDATE_MESSAGE_FLAGS' =
50+
'EVENT_UPDATE_MESSAGE_FLAGS';
51+
export const EVENT_USER_ADD: 'EVENT_USER_ADD' = 'EVENT_USER_ADD';
52+
export const EVENT_USER_REMOVE: 'EVENT_USER_REMOVE' = 'EVENT_USER_REMOVE';
53+
export const EVENT_USER_UPDATE: 'EVENT_USER_UPDATE' = 'EVENT_USER_UPDATE';
54+
export const EVENT_MUTED_TOPICS: 'EVENT_MUTED_TOPICS' = 'EVENT_MUTED_TOPICS';
55+
56+
export const EVENT_USER_GROUP_ADD: 'EVENT_USER_GROUP_ADD' = 'EVENT_USER_GROUP_ADD';
57+
export const EVENT_USER_GROUP_REMOVE: 'EVENT_USER_GROUP_REMOVE' = 'EVENT_USER_GROUP_REMOVE';
58+
export const EVENT_USER_GROUP_UPDATE: 'EVENT_USER_GROUP_UPDATE' = 'EVENT_USER_GROUP_UPDATE';
59+
export const EVENT_USER_GROUP_ADD_MEMBERS: 'EVENT_USER_GROUP_ADD_MEMBERS' =
60+
'EVENT_USER_GROUP_ADD_MEMBERS';
61+
export const EVENT_USER_GROUP_REMOVE_MEMBERS: 'EVENT_USER_GROUP_REMOVE_MEMBERS' =
62+
'EVENT_USER_GROUP_REMOVE_MEMBERS';
63+
64+
export const MESSAGE_FETCH_START: 'MESSAGE_FETCH_START' = 'MESSAGE_FETCH_START';
65+
export const MESSAGE_FETCH_COMPLETE: 'MESSAGE_FETCH_COMPLETE' = 'MESSAGE_FETCH_COMPLETE';
66+
67+
export const PRESENCE_RESPONSE: 'PRESENCE_RESPONSE' = 'PRESENCE_RESPONSE';
68+
export const GET_USER_RESPONSE: 'GET_USER_RESPONSE' = 'GET_USER_RESPONSE';
69+
export const MARK_MESSAGES_READ: 'MARK_MESSAGES_READ' = 'MARK_MESSAGES_READ';
70+
export const SETTINGS_CHANGE: 'SETTINGS_CHANGE' = 'SETTINGS_CHANGE';
71+
export const DEBUG_FLAG_TOGGLE: 'DEBUG_FLAG_TOGGLE' = 'DEBUG_FLAG_TOGGLE';
72+
73+
export const GOT_PUSH_TOKEN: 'GOT_PUSH_TOKEN' = 'GOT_PUSH_TOKEN';
74+
export const ACK_PUSH_TOKEN: 'ACK_PUSH_TOKEN' = 'ACK_PUSH_TOKEN';
75+
export const UNACK_PUSH_TOKEN: 'UNACK_PUSH_TOKEN' = 'UNACK_PUSH_TOKEN';
76+
77+
export const EVENT_REALM_EMOJI_UPDATE: 'EVENT_REALM_EMOJI_UPDATE' = 'EVENT_REALM_EMOJI_UPDATE';
78+
export const EVENT_REALM_FILTERS: 'EVENT_REALM_FILTERS' = 'EVENT_REALM_FILTERS';
79+
80+
export const EVENT_UPDATE_DISPLAY_SETTINGS: 'EVENT_UPDATE_DISPLAY_SETTINGS' =
81+
'EVENT_UPDATE_DISPLAY_SETTINGS';
82+
export const EVENT_UPDATE_GLOBAL_NOTIFICATIONS_SETTINGS: 'EVENT_UPDATE_GLOBAL_NOTIFICATIONS_SETTINGS' =
7783
'EVENT_UPDATE_GLOBAL_NOTIFICATIONS_SETTINGS';
7884

79-
export const START_EDIT_MESSAGE = 'START_EDIT_MESSAGE';
80-
export const CANCEL_EDIT_MESSAGE = 'CANCEL_EDIT_MESSAGE';
85+
export const START_EDIT_MESSAGE: 'START_EDIT_MESSAGE' = 'START_EDIT_MESSAGE';
86+
export const CANCEL_EDIT_MESSAGE: 'CANCEL_EDIT_MESSAGE' = 'CANCEL_EDIT_MESSAGE';
8187

82-
export const INIT_ALERT_WORDS = 'INIT_ALERT_WORDS';
88+
export const INIT_ALERT_WORDS: 'INIT_ALERT_WORDS' = 'INIT_ALERT_WORDS';
8389

84-
export const MESSAGE_SEND_START = 'MESSAGE_SEND_START';
85-
export const MESSAGE_SEND_COMPLETE = 'MESSAGE_SEND_COMPLETE';
90+
export const MESSAGE_SEND_START: 'MESSAGE_SEND_START' = 'MESSAGE_SEND_START';
91+
export const MESSAGE_SEND_COMPLETE: 'MESSAGE_SEND_COMPLETE' = 'MESSAGE_SEND_COMPLETE';
8692

87-
export const TOGGLE_OUTBOX_SENDING = 'TOGGLE_OUTBOX_SENDING';
88-
export const DELETE_OUTBOX_MESSAGE = 'DELETE_OUTBOX_MESSAGE';
93+
export const TOGGLE_OUTBOX_SENDING: 'TOGGLE_OUTBOX_SENDING' = 'TOGGLE_OUTBOX_SENDING';
94+
export const DELETE_OUTBOX_MESSAGE: 'DELETE_OUTBOX_MESSAGE' = 'DELETE_OUTBOX_MESSAGE';
8995

90-
export const DRAFT_UPDATE = 'DRAFT_UPDATE';
96+
export const DRAFT_UPDATE: 'DRAFT_UPDATE' = 'DRAFT_UPDATE';
9197

92-
export const CLEAR_TYPING = 'CLEAR_TYPING';
98+
export const CLEAR_TYPING: 'CLEAR_TYPING' = 'CLEAR_TYPING';

‎src/actionTypes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ type DraftsAction = DraftUpdateAction;
643643

644644
type LoadingAction = DeadQueueAction | InitialFetchStartAction | InitialFetchCompleteAction;
645645

646-
type MessageAction = MessageFetchStartAction | MessageFetchCompleteAction;
646+
type MessageAction = MarkMessagesReadAction | MessageFetchStartAction | MessageFetchCompleteAction;
647647

648648
type OutboxAction = MessageSendStartAction | MessageSendCompleteAction | DeleteOutboxMessageAction;
649649

‎src/boot/__tests__/reducers-test.js

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { discardKeys, storeKeys, cacheKeys } from '../../boot/store';
44

55
describe('reducers', () => {
66
test('reducers return the default states on unknown action', () => {
7+
// $FlowFixMe bogus action object
78
expect(() => reducers({}, { type: 'UNKNOWN_ACTION' })).not.toThrow();
89
});
910

‎src/caughtup/__tests__/caughtUpReducers-test.js

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe('caughtUpReducers', () => {
2626
narrow: HOME_NARROW,
2727
});
2828

29+
// $FlowFixMe bogus action object
2930
const newState = caughtUpReducers(initialState, action);
3031

3132
expect(newState).toBe(initialState);

‎src/loading/__tests__/loadingReducer-test.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ describe('loadingReducers', () => {
1717

1818
const action = deepFreeze({
1919
type: ACCOUNT_SWITCH,
20+
index: 1,
2021
});
2122

2223
const expectedState = {

0 commit comments

Comments
 (0)
Please sign in to comment.