Skip to content

Commit 67bed79

Browse files
fix: replace StreamChatGenerics with module augmentation (#2634)
### 🎯 Goal References: GetStream/stream-chat-js#1458 #### Notable changes: - Extended `EventComponentProps.message` property with `{ event?: Event }` to cover for weird edge-case - Extended `StreamMessage` type with these properties commonly used across the SDK `{ customType?: string; errorStatusCode?: number; editing?: boolean; date?: Date }` BREAKING CHANGE: dropped `StreamChatGenerics`, use `Custom<Entity>Data` to extend your types
1 parent 50ee29c commit 67bed79

File tree

285 files changed

+2620
-4587
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

285 files changed

+2620
-4587
lines changed

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export default tseslint.config(
9191
{ ignoreRestSiblings: false, caughtErrors: 'none' },
9292
],
9393
'@typescript-eslint/no-unsafe-function-type': 'error',
94+
'@typescript-eslint/consistent-type-imports': 'error',
9495
'@typescript-eslint/no-wrapper-object-types': 'error',
9596
'@typescript-eslint/no-non-null-assertion': 'error',
9697
'no-empty-function': 'off',

examples/capacitor/src/App.tsx

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,7 @@ const filters: ChannelFilters = { type: 'messaging', members: { $in: [userId] }
2121
const options: ChannelOptions = { state: true, presence: true, limit: 10 };
2222
const sort: ChannelSort = { last_message_at: -1, updated_at: -1 };
2323

24-
type LocalAttachmentType = Record<string, unknown>;
25-
type LocalChannelType = Record<string, unknown>;
26-
type LocalCommandType = string;
27-
type LocalEventType = Record<string, unknown>;
28-
type LocalMessageType = Record<string, unknown>;
29-
type LocalReactionType = Record<string, unknown>;
30-
type LocalUserType = Record<string, unknown>;
31-
32-
type StreamChatGenerics = {
33-
attachmentType: LocalAttachmentType;
34-
channelType: LocalChannelType;
35-
commandType: LocalCommandType;
36-
eventType: LocalEventType;
37-
messageType: LocalMessageType;
38-
reactionType: LocalReactionType;
39-
userType: LocalUserType;
40-
};
41-
42-
const chatClient = StreamChat.getInstance<StreamChatGenerics>(apiKey);
24+
const chatClient = StreamChat.getInstance(apiKey);
4325

4426
if (process.env.REACT_APP_CHAT_SERVER_ENDPOINT) {
4527
chatClient.setBaseURL(process.env.REACT_APP_CHAT_SERVER_ENDPOINT);

examples/typescript/src/App.tsx

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,7 @@ const filters: ChannelFilters = { type: 'messaging', members: { $in: [userId] }
2323
const options: ChannelOptions = { state: true, presence: true, limit: 10 };
2424
const sort: ChannelSort = { last_message_at: -1, updated_at: -1 };
2525

26-
type LocalAttachmentType = Record<string, unknown>;
27-
type LocalChannelType = Record<string, unknown>;
28-
type LocalCommandType = string;
29-
type LocalEventType = Record<string, unknown>;
30-
type LocalMemberType = Record<string, unknown>;
31-
type LocalMessageType = Record<string, unknown>;
32-
type LocalPollOptionType = Record<string, unknown>;
33-
type LocalPollType = Record<string, unknown>;
34-
type LocalReactionType = Record<string, unknown>;
35-
type LocalUserType = Record<string, unknown>;
36-
37-
type StreamChatGenerics = {
38-
attachmentType: LocalAttachmentType;
39-
channelType: LocalChannelType;
40-
commandType: LocalCommandType;
41-
eventType: LocalEventType;
42-
memberType: LocalMemberType;
43-
messageType: LocalMessageType;
44-
pollOptionType: LocalPollOptionType;
45-
pollType: LocalPollType;
46-
reactionType: LocalReactionType;
47-
userType: LocalUserType;
48-
};
49-
50-
const chatClient = StreamChat.getInstance<StreamChatGenerics>(apiKey);
26+
const chatClient = StreamChat.getInstance(apiKey);
5127

5228
if (process.env.REACT_APP_CHAT_SERVER_ENDPOINT) {
5329
chatClient.setBaseURL(process.env.REACT_APP_CHAT_SERVER_ENDPOINT);

examples/vite/src/App.tsx

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,35 +40,10 @@ const filters: ChannelFilters = {
4040
const options: ChannelOptions = { limit: 5, presence: true, state: true };
4141
const sort: ChannelSort = { pinned_at: 1, last_message_at: -1, updated_at: -1 };
4242

43-
type LocalAttachmentType = Record<string, unknown>;
44-
type LocalChannelType = Record<string, unknown>;
45-
type LocalCommandType = string;
46-
type LocalEventType = Record<string, unknown>;
47-
type LocalMemberType = Record<string, unknown>;
48-
type LocalMessageType = Record<string, unknown>;
49-
type LocalPollOptionType = Record<string, unknown>;
50-
type LocalPollType = Record<string, unknown>;
51-
type LocalReactionType = Record<string, unknown>;
52-
type LocalUserType = Record<string, unknown>;
53-
54-
type StreamChatGenerics = {
55-
attachmentType: LocalAttachmentType;
56-
channelType: LocalChannelType;
57-
commandType: LocalCommandType;
58-
eventType: LocalEventType;
59-
memberType: LocalMemberType;
60-
messageType: LocalMessageType;
61-
pollOptionType: LocalPollOptionType;
62-
pollType: LocalPollType;
63-
reactionType: LocalReactionType;
64-
userType: LocalUserType;
65-
};
66-
67-
const isMessageAIGenerated = (message: StreamMessage<StreamChatGenerics>) =>
68-
!!message?.ai_generated;
43+
const isMessageAIGenerated = (message: StreamMessage) => !!message?.ai_generated;
6944

7045
const App = () => {
71-
const chatClient = useCreateChatClient<StreamChatGenerics>({
46+
const chatClient = useCreateChatClient({
7247
apiKey,
7348
tokenOrProvider: userToken,
7449
userData: { id: userId },

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@
239239
"react": "^19.0.0",
240240
"react-dom": "^19.0.0",
241241
"semantic-release": "^24.2.3",
242-
"stream-chat": "^8.55.0",
242+
"stream-chat": "^9.0.0-rc.8",
243243
"ts-jest": "^29.2.5",
244244
"typescript": "^5.4.5",
245245
"typescript-eslint": "^8.17.0"
@@ -260,7 +260,7 @@
260260
"prepare": "husky install",
261261
"preversion": "yarn install",
262262
"test": "jest",
263-
"types": "tsc --noEmit --skipLibCheck false",
263+
"types": "tsc --noEmit",
264264
"validate-translations": "node scripts/validate-translations.js",
265265
"validate-cjs": "concurrently 'node scripts/validate-cjs-node-bundle.cjs' 'node scripts/validate-cjs-browser-bundle.cjs'",
266266
"semantic-release": "semantic-release",

src/@types/image-files.d.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import 'stream-chat';
2+
3+
declare module 'stream-chat' {
4+
interface CustomChannelData {
5+
image?: string;
6+
name?: string;
7+
subtitle?: string;
8+
}
9+
}

src/@types/vfile-message.d.ts

Lines changed: 0 additions & 98 deletions
This file was deleted.

src/components/AIStateIndicator/AIStateIndicator.tsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
import React from 'react';
2-
3-
import { Channel } from 'stream-chat';
2+
import type { Channel } from 'stream-chat';
43

54
import { AIStates, useAIState } from './hooks/useAIState';
65

76
import { useChannelStateContext, useTranslationContext } from '../../context';
8-
import type { DefaultStreamChatGenerics } from '../../types/types';
97

10-
export type AIStateIndicatorProps<
11-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
12-
> = {
13-
channel?: Channel<StreamChatGenerics>;
8+
export type AIStateIndicatorProps = {
9+
channel?: Channel;
1410
};
1511

16-
export const AIStateIndicator = <
17-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
18-
>({
12+
export const AIStateIndicator = ({
1913
channel: channelFromProps,
20-
}: AIStateIndicatorProps<StreamChatGenerics>) => {
14+
}: AIStateIndicatorProps) => {
2115
const { t } = useTranslationContext();
22-
const { channel: channelFromContext } =
23-
useChannelStateContext<StreamChatGenerics>('AIStateIndicator');
16+
const { channel: channelFromContext } = useChannelStateContext('AIStateIndicator');
2417
const channel = channelFromProps || channelFromContext;
2518
const { aiState } = useAIState(channel);
2619
const allowedStates = {

src/components/AIStateIndicator/hooks/useAIState.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { useEffect, useState } from 'react';
2-
3-
import { AIState, Channel, Event } from 'stream-chat';
4-
5-
import type { DefaultStreamChatGenerics } from '../../../types/types';
2+
import type { AIState, Channel, Event } from 'stream-chat';
63

74
export const AIStates = {
85
Error: 'AI_STATE_ERROR',
@@ -17,28 +14,21 @@ export const AIStates = {
1714
* @param {Channel} channel - The channel for which we want to know the AI state.
1815
* @returns {{ aiState: AIState }} The current AI state for the given channel.
1916
*/
20-
export const useAIState = <
21-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
22-
>(
23-
channel?: Channel<StreamChatGenerics>,
24-
): { aiState: AIState } => {
17+
export const useAIState = (channel?: Channel): { aiState: AIState } => {
2518
const [aiState, setAiState] = useState<AIState>(AIStates.Idle);
2619

2720
useEffect(() => {
2821
if (!channel) {
2922
return;
3023
}
3124

32-
const indicatorChangedListener = channel.on(
33-
'ai_indicator.update',
34-
(event: Event<StreamChatGenerics>) => {
35-
const { cid } = event;
36-
const state = event.ai_state as AIState;
37-
if (channel.cid === cid) {
38-
setAiState(state);
39-
}
40-
},
41-
);
25+
const indicatorChangedListener = channel.on('ai_indicator.update', (event: Event) => {
26+
const { cid } = event;
27+
const state = event.ai_state as AIState;
28+
if (channel.cid === cid) {
29+
setAiState(state);
30+
}
31+
});
4232

4333
const indicatorClearedListener = channel.on('ai_indicator.clear', (event) => {
4434
const { cid } = event;

0 commit comments

Comments
 (0)