You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docusaurus/docs/reactnative/customization/typescript.mdx
+57-47Lines changed: 57 additions & 47 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,20 +21,48 @@ In many cases TypeScript can use [inference](https://www.typescriptlang.org/docs
21
21
22
22
It is important that the proper generics be applied to the `stream-chat-js` client when it is instantiated.
23
23
The [documentation on `stream-chat-js` TypeScript](https://github.com/GetStream/stream-chat-js#typescript-v2xx) has examples of how this can be done in detail.
24
-
The client takes seven optional generics that correspond to the seven customizable fields that currently exist in `stream-chat-js`.
24
+
The client takes seven generics that correspond to the seven customizable fields that currently exist in `stream-chat-js`.
All seven generics contain defaults in the `stream-chat-react-native` repo that you can extend for custom data.
76
+
All seven generics contain defaults in the `stream-chat-react-native` repo that you can extend for custom data as per your types for the Channel, Message, etc.
Additional fields on the defaults i.e. `file_size`, `mime_type`, and `image` are custom fields used by `stream-chat-react-native` already within the SDK.
92
+
Additional fields on the defaults i.e. `image` are custom fields used by `stream-chat-react-native` already within the SDK.
68
93
When wanting to set a subset of generics the preceding and interceding generics must also be set in order for the TypeScript compiler to correctly understand intent.
69
94
70
-
To set `ChannelType` and `MessageType` for `AttachmentType`, `CommandType`, and `EventType` must also be set.
@@ -92,7 +121,7 @@ The [TypeScript Example App](https://github.com/GetStream/stream-chat-react-nati
92
121
Core to understanding this usage is [how generics can be applied to JSX elements](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-9.html#generic-type-arguments-in-jsx-elements).
93
122
94
123
In many cases the use of a single prop such as `client` or `channel` allows TypeScript to infer the generics on an element.
95
-
In this case `LocalAttachmentType` is inferred from `channel` and passed to the props type for a custom Attachment component.
124
+
In this case `StreamChatType` is inferred from `channel` and passed to the props type for a custom Attachment component.
96
125
97
126
<imgsrc={inference}alt='TypeScript Inference' />
98
127
@@ -101,13 +130,7 @@ In these cases the generics must be applied to the component directly.
101
130
`MessageList` for instance could have the previous generics used on `client` applied to it in a similar manner.
102
131
103
132
```tsx
104
-
<MessageList<
105
-
DefaultAttachmentType,
106
-
{ image?:string; nickName?:string },
107
-
DefaultCommandType,
108
-
DefaultEventType,
109
-
{ isAdminMessage?:boolean }
110
-
>
133
+
<MessageList<StreamChatType>
111
134
onThreadSelect={thread=> {
112
135
/** Set thread and navigate to thread screen */
113
136
}}
@@ -124,13 +147,7 @@ Hooks, including those to access contexts, also require generics to be applied t
124
147
`useChannelContext` for instance would have the previous generics applied to it to get a correctly typed return for `channel`.
@@ -144,12 +161,5 @@ The lack of partial inference is particularly relevant if Higher Order Component
144
161
The `withChannelContext` HOC accepts the generics similarly to the `useChannelContext` hook, but because partial inference is not supported the props for the wrapped component must also be explicitly provided.
0 commit comments