Skip to content

Commit c6a4f4d

Browse files
authored
Demos: Fix TS problems and make TS improvements in demos in strict mode (Editors) (#32079) (#32097)
Signed-off-by: Andrei Kharitonov <[email protected]>
1 parent 8a9ed83 commit c6a4f4d

File tree

62 files changed

+247
-263
lines changed

Some content is hidden

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

62 files changed

+247
-263
lines changed

apps/demos/Demos/Autocomplete/Overview/React/App.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ const clientsStore = new CustomStore({
2323
useDefaultSearch: true,
2424
load: (loadOptions: LoadOptions) => {
2525
let params = '?';
26-
['skip', 'take', 'filter'].forEach((option: string): void => {
26+
type LoadOptionKey = keyof LoadOptions;
27+
const loadOptionKeys: LoadOptionKey[] = ['skip', 'take', 'filter'];
28+
loadOptionKeys.forEach((option: LoadOptionKey): void => {
2729
if (option in loadOptions && isNotEmpty(loadOptions[option])) {
28-
params += `${option}=${JSON.stringify(loadOptions[option])}&`;
30+
params += `${option as string}=${JSON.stringify(loadOptions[option])}&`;
2931
}
3032
});
3133
params = params.slice(0, -1);

apps/demos/Demos/Autocomplete/Overview/ReactJs/App.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ const clientsStore = new CustomStore({
1919
useDefaultSearch: true,
2020
load: (loadOptions) => {
2121
let params = '?';
22-
['skip', 'take', 'filter'].forEach((option) => {
22+
const loadOptionKeys = ['skip', 'take', 'filter'];
23+
loadOptionKeys.forEach((option) => {
2324
if (option in loadOptions && isNotEmpty(loadOptions[option])) {
2425
params += `${option}=${JSON.stringify(loadOptions[option])}&`;
2526
}

apps/demos/Demos/Calendar/MultipleSelection/React/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default function App() {
6666
min={minDateValue}
6767
max={maxDateValue}
6868
defaultValue={initialValue}
69-
disabledDates={weekendDisabled ? isDateDisabled : null}
69+
disabledDates={weekendDisabled ? isDateDisabled : undefined}
7070
/>
7171
</div>
7272
<div className="options">

apps/demos/Demos/Calendar/MultipleSelection/ReactJs/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default function App() {
6565
min={minDateValue}
6666
max={maxDateValue}
6767
defaultValue={initialValue}
68-
disabledDates={weekendDisabled ? isDateDisabled : null}
68+
disabledDates={weekendDisabled ? isDateDisabled : undefined}
6969
/>
7070
</div>
7171
<div className="options">

apps/demos/Demos/Calendar/Overview/React/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const ruleLabel = { 'aria-label': 'Week Number Rule' };
2727

2828
export default function App() {
2929
const [zoomLevel, setZoomLevel] = useState<CalendarTypes.CalendarZoomLevel>('month');
30-
const [currentValue, setCurrentValue] = useState<Date>(new Date());
30+
const [currentValue, setCurrentValue] = useState<Date | undefined>(new Date());
3131
const [useCellTemplate, setUseCellTemplate] = useState<boolean | null>(null);
3232
const [disabled, setDisabled] = useState<boolean>(false);
3333
const [showWeekNumbers, setShowWeekNumbers] = useState<boolean>(false);
@@ -104,7 +104,7 @@ export default function App() {
104104
showWeekNumbers={showWeekNumbers}
105105
disabled={disabled}
106106
zoomLevel={zoomLevel}
107-
cellComponent={useCellTemplate ? CustomCell : null}
107+
cellComponent={useCellTemplate ? CustomCell : undefined}
108108
/>
109109
</div>
110110
<div className="options">

apps/demos/Demos/Calendar/Overview/ReactJs/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export default function App() {
7575
showWeekNumbers={showWeekNumbers}
7676
disabled={disabled}
7777
zoomLevel={zoomLevel}
78-
cellComponent={useCellTemplate ? CustomCell : null}
78+
cellComponent={useCellTemplate ? CustomCell : undefined}
7979
/>
8080
</div>
8181
<div className="options">

apps/demos/Demos/Chat/AIAndChatbotIntegration/React/App.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useCallback, useState } from 'react';
2-
import Chat, { type ChatTypes } from 'devextreme-react/chat';
2+
import Chat from 'devextreme-react/chat';
3+
import type { ChatTypes } from 'devextreme-react/chat';
34
import { loadMessages } from 'devextreme-react/common/core/localization';
45
import {
56
user,
@@ -42,11 +43,11 @@ export default function App() {
4243
insertMessage({ id: Date.now(), ...message });
4344

4445
if (!alerts.length) {
45-
(event.target as HTMLElement).blur();
46+
(event?.target as HTMLElement).blur();
4647

4748
await processAIRequest(message);
4849

49-
(event.target as HTMLElement).focus();
50+
(event?.target as HTMLElement).focus();
5051
}
5152
}, [insertMessage, alerts.length, processAIRequest]);
5253

apps/demos/Demos/Chat/AIAndChatbotIntegration/React/useApi.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { useCallback, useState } from 'react';
22
import { AzureOpenAI, OpenAI } from 'openai';
3-
import { type ChatTypes } from 'devextreme-react/chat';
3+
import type { ChatTypes } from 'devextreme-react/chat';
44
import { CustomStore, DataSource } from 'devextreme-react/common/data';
5+
import type { AIResponse } from 'devextreme/common/ai-integration';
56
import {
6-
ALERT_TIMEOUT, assistant,
7-
AzureOpenAIConfig, REGENERATION_TEXT,
7+
ALERT_TIMEOUT,
8+
assistant,
9+
AzureOpenAIConfig,
10+
REGENERATION_TEXT,
811
} from './data.ts';
912

1013
type Message = (OpenAI.ChatCompletionUserMessageParam | OpenAI.ChatCompletionAssistantMessageParam) & {
@@ -14,11 +17,11 @@ type Message = (OpenAI.ChatCompletionUserMessageParam | OpenAI.ChatCompletionAss
1417
const chatService = new AzureOpenAI(AzureOpenAIConfig);
1518

1619
const wait = (delay: number): Promise<void> =>
17-
new Promise((resolve) => {
20+
new Promise((resolve): void => {
1821
setTimeout(resolve, delay);
1922
});
2023

21-
export async function getAIResponse(messages: Message[], delay?: number): Promise<string> {
24+
export async function getAIResponse(messages: Message[], delay?: number): Promise<AIResponse> {
2225
const params = {
2326
messages,
2427
model: AzureOpenAIConfig.deployment,
@@ -33,7 +36,7 @@ export async function getAIResponse(messages: Message[], delay?: number): Promis
3336
await wait(delay);
3437
}
3538

36-
return data.choices[0].message?.content;
39+
return data.choices[0].message?.content ?? '';
3740
}
3841

3942
const store: ChatTypes.Message[] = [];
@@ -59,7 +62,7 @@ export const dataSource = new DataSource({
5962
});
6063

6164
const dataItemToMessage = (item: ChatTypes.Message): Message => ({
62-
role: item.author.id as Message['role'],
65+
role: item.author?.id as Message['role'],
6366
content: item.text,
6467
});
6568

@@ -116,9 +119,11 @@ export const useApi = () => {
116119
try {
117120
const aiResponse = await getAIResponse(messageHistory.slice(0, -1));
118121

119-
updateLastMessageContent(aiResponse);
122+
if (typeof aiResponse === 'string') {
123+
updateLastMessageContent(aiResponse);
124+
}
120125
} catch {
121-
updateLastMessageContent(messageHistory.at(-1)?.content);
126+
updateLastMessageContent(messageHistory.at(-1)?.content as string);
122127
alertLimitReached();
123128
}
124129
}, [alertLimitReached, updateLastMessageContent]);

apps/demos/Demos/Chat/AIAndChatbotIntegration/ReactJs/App.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ export default function App() {
3232
async ({ message, event }) => {
3333
insertMessage({ id: Date.now(), ...message });
3434
if (!alerts.length) {
35-
event.target.blur();
35+
(event?.target).blur();
3636
await processAIRequest(message);
37-
event.target.focus();
37+
(event?.target).focus();
3838
}
3939
},
4040
[insertMessage, alerts.length, processAIRequest],

apps/demos/Demos/Chat/AIAndChatbotIntegration/ReactJs/useApi.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export async function getAIResponse(messages, delay) {
2222
if (delay) {
2323
await wait(delay);
2424
}
25-
return data.choices[0].message?.content;
25+
return data.choices[0].message?.content ?? '';
2626
}
2727
const store = [];
2828
const customStore = new CustomStore({
@@ -46,7 +46,7 @@ export const dataSource = new DataSource({
4646
paginate: false,
4747
});
4848
const dataItemToMessage = (item) => ({
49-
role: item.author.id,
49+
role: item.author?.id,
5050
content: item.text,
5151
});
5252
const getMessageHistory = () => [...dataSource.items()].map(dataItemToMessage);
@@ -97,7 +97,9 @@ export const useApi = () => {
9797
updateLastMessageContent(REGENERATION_TEXT);
9898
try {
9999
const aiResponse = await getAIResponse(messageHistory.slice(0, -1));
100-
updateLastMessageContent(aiResponse);
100+
if (typeof aiResponse === 'string') {
101+
updateLastMessageContent(aiResponse);
102+
}
101103
} catch {
102104
updateLastMessageContent(messageHistory.at(-1)?.content);
103105
alertLimitReached();

0 commit comments

Comments
 (0)