Skip to content

Commit 34bf18b

Browse files
committed
types: Use SubsetProperties to base Outbox more directly on Message.
This actually turned up one small discrepancy! The `reactions` property's type was plain `Reaction[]` here, but over on Message it's `$ReadOnlyArray<Reaction>`. While we're closely comparing these, also add a `$ReadOnly` on the whole type to match the one on `Message`.
1 parent 76cefa4 commit 34bf18b

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

src/types.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import type { IntlShape } from 'react-intl';
33
import type { DangerouslyImpreciseStyleProp } from 'react-native/Libraries/StyleSheet/StyleSheet';
44

5-
import type { Auth, Topic, Message, PmRecipientUser, Reaction, ReactionType } from './api/apiTypes';
5+
import type { SubsetProperties } from './generics';
6+
import type { Auth, Topic, Message, ReactionType } from './api/apiTypes';
67
import type { ZulipVersion } from './utils/zulipVersion';
78

89
export type * from './generics';
@@ -158,7 +159,7 @@ export type TopicExtended = {|
158159
* This type most often appears in the union `Message | Outbox`, and so its
159160
* properties are deliberately similar to those of `Message`.
160161
*/
161-
export type Outbox = {|
162+
export type Outbox = $ReadOnly<{|
162163
/** Used for distinguishing from a `Message` object. */
163164
isOutbox: true,
164165

@@ -177,24 +178,29 @@ export type Outbox = {|
177178

178179
// The remaining fields are modeled on `Message`.
179180

180-
avatar_url: string | null,
181-
content: string,
182-
display_recipient: string | $ReadOnlyArray<PmRecipientUser>, // `string` for type stream, else PmRecipientUser[]
183-
id: number,
184-
reactions: Reaction[],
185-
sender_email: string,
186-
sender_full_name: string,
187-
188181
// TODO(#3764): Make sender_id required. Needs a migration to drop Outbox
189182
// values that lack it; which is fine once the release that adds it has
190183
// been out for a few weeks.
191184
// (Also drop the hack line about it in MessageLike.)
192185
sender_id?: number,
193186

194-
subject: string,
195-
timestamp: number,
196-
type: 'stream' | 'private',
197-
|};
187+
/* eslint-disable flowtype/generic-spacing */
188+
...SubsetProperties<
189+
Message,
190+
{|
191+
avatar_url: mixed,
192+
content: mixed,
193+
display_recipient: mixed,
194+
id: mixed,
195+
reactions: mixed,
196+
sender_email: mixed,
197+
sender_full_name: mixed,
198+
subject: mixed,
199+
timestamp: mixed,
200+
type: mixed,
201+
|},
202+
>,
203+
|}>;
198204

199205
/**
200206
* MessageLike: Imprecise alternative to `Message | Outbox`.

0 commit comments

Comments
 (0)