Skip to content

Commit 0d52900

Browse files
authored
Demos: Fix TS problems and make TS improvements in strict mode (Navigation) (#32072) (#32078)
1 parent 081ec81 commit 0d52900

File tree

142 files changed

+879
-594
lines changed

Some content is hidden

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

142 files changed

+879
-594
lines changed

apps/demos/Demos/Button/PredefinedTypes/React/App.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import React from 'react';
2-
import { Button, type ButtonTypes } from 'devextreme-react/button';
2+
import { Button } from 'devextreme-react/button';
3+
import type { ButtonTypes } from 'devextreme-react/button';
34
import notify from 'devextreme/ui/notify';
45

5-
const onClick = (e: ButtonTypes.ClickEvent) => {
6-
const buttonText = e.component.option('text');
6+
const onClick = (e: ButtonTypes.ClickEvent): void => {
7+
const buttonText = e.component.option('text') ?? '';
78
notify(`The ${capitalize(buttonText)} button was clicked`);
89
};
910

10-
function capitalize(text: string) {
11+
function capitalize(text: string): string {
1112
return text.charAt(0).toUpperCase() + text.slice(1);
1213
}
1314

apps/demos/Demos/Button/PredefinedTypes/ReactJs/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Button } from 'devextreme-react/button';
33
import notify from 'devextreme/ui/notify';
44

55
const onClick = (e) => {
6-
const buttonText = e.component.option('text');
6+
const buttonText = e.component.option('text') ?? '';
77
notify(`The ${capitalize(buttonText)} button was clicked`);
88
};
99
function capitalize(text) {

apps/demos/Demos/Charts/AjaxRequest/React/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Chart, {
99
Tick,
1010
} from 'devextreme-react/chart';
1111

12-
const customizeText = (e) => `Day ${e.value}`;
12+
const customizeText = (e: { value: string | number | Date }): string => `Day ${e.value}`;
1313

1414
function App() {
1515
return (

apps/demos/Demos/Charts/Annotation/React/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from 'devextreme-react/chart';
1515
import { dataSource, annotationSources } from './data.ts';
1616

17-
const customizeTooltip = (annotation) => ({
17+
const customizeTooltip = (annotation: { description: string }): Record<string, string> => ({
1818
html: `<div class='tooltip'>${annotation.description}</div>`,
1919
});
2020

apps/demos/Demos/Charts/AreaSelectionZooming/React/App.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ import Chart, {
1111
Crosshair,
1212
Legend,
1313
Border,
14-
type ChartTypes,
1514
} from 'devextreme-react/chart';
15+
import type { ChartTypes, ChartRef } from 'devextreme-react/chart';
1616
import Button from 'devextreme-react/button';
1717
import { birthLife } from './data.ts';
1818

19-
function customizeTooltip(pointInfo: ChartTypes.CommonPointInfo) {
20-
const { data } = pointInfo.point;
19+
function customizeTooltip(pointInfo: ChartTypes.CommonPointInfo): Record<string, string> {
20+
const { data } = pointInfo.point ?? {};
2121
return {
2222
text: `${data.country} ${data.year}`,
2323
};
2424
}
2525

2626
function App() {
27-
const chartRef = useRef(null);
27+
const chartRef = useRef<ChartRef>(null);
2828

2929
const resetZoom = useCallback(() => {
30-
chartRef.current.instance().resetVisualRange();
30+
chartRef.current?.instance().resetVisualRange();
3131
}, []);
3232

3333
return (

apps/demos/Demos/Charts/AreaSelectionZooming/ReactJs/App.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ import Button from 'devextreme-react/button';
1616
import { birthLife } from './data.js';
1717

1818
function customizeTooltip(pointInfo) {
19-
const { data } = pointInfo.point;
19+
const { data } = pointInfo.point ?? {};
2020
return {
2121
text: `${data.country} ${data.year}`,
2222
};
2323
}
2424
function App() {
2525
const chartRef = useRef(null);
2626
const resetZoom = useCallback(() => {
27-
chartRef.current.instance().resetVisualRange();
27+
chartRef.current?.instance().resetVisualRange();
2828
}, []);
2929
return (
3030
<div>

apps/demos/Demos/Charts/BarDrillDown/React/App.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import {
44
Series,
55
Legend,
66
ValueAxis,
7-
type ChartTypes,
87
} from 'devextreme-react/chart';
8+
import type { ChartTypes } from 'devextreme-react/chart';
99
import { Button } from 'devextreme-react/button';
1010
import service from './data.ts';
1111

1212
const colors = ['#6babac', '#e55253'];
1313

1414
function App() {
15-
const [isFirstLevel, setIsFirstLevel] = useState(true);
15+
const [isFirstLevel, setIsFirstLevel] = useState<boolean>(true);
1616
const [data, setData] = useState(service.filterData(''));
1717

1818
const customizePoint = useCallback((): {
@@ -28,19 +28,19 @@ function App() {
2828
} : {},
2929
}), [isFirstLevel]);
3030

31-
const onPointClick = useCallback((e: ChartTypes.PointClickEvent) => {
31+
const onPointClick = useCallback((e: ChartTypes.PointClickEvent): void => {
3232
if (isFirstLevel) {
3333
setIsFirstLevel(false);
34-
setData(service.filterData(e.target.originalArgument.toString()));
34+
setData(service.filterData(e.target.originalArgument?.toString() ?? ''));
3535
}
36-
}, [isFirstLevel, setData, setIsFirstLevel]);
36+
}, [isFirstLevel]);
3737

3838
const onButtonClick = useCallback(() => {
3939
if (!isFirstLevel) {
4040
setIsFirstLevel(true);
4141
setData(service.filterData(''));
4242
}
43-
}, [isFirstLevel, setData, setIsFirstLevel]);
43+
}, [isFirstLevel]);
4444

4545
return (
4646
<div>

apps/demos/Demos/Charts/BarDrillDown/ReactJs/App.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ function App() {
2424
(e) => {
2525
if (isFirstLevel) {
2626
setIsFirstLevel(false);
27-
setData(service.filterData(e.target.originalArgument.toString()));
27+
setData(service.filterData(e.target.originalArgument?.toString() ?? ''));
2828
}
2929
},
30-
[isFirstLevel, setData, setIsFirstLevel],
30+
[isFirstLevel],
3131
);
3232
const onButtonClick = useCallback(() => {
3333
if (!isFirstLevel) {
3434
setIsFirstLevel(true);
3535
setData(service.filterData(''));
3636
}
37-
}, [isFirstLevel, setData, setIsFirstLevel]);
37+
}, [isFirstLevel]);
3838
return (
3939
<div>
4040
<Chart

apps/demos/Demos/Charts/Bubble/React/App.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ import {
1010
Border,
1111
Tooltip,
1212
Export,
13-
type ChartTypes,
1413
} from 'devextreme-react/chart';
14+
import type { ChartTypes } from 'devextreme-react/chart';
1515
import { dataSource } from './data.ts';
1616

17-
const palette = ['#00ced1', '#008000', '#ffd700', '#ff7f50'];
17+
const palette: string[] = ['#00ced1', '#008000', '#ffd700', '#ff7f50'];
1818

19-
const customizeTooltip = (pointInfo) => ({
20-
text: `${pointInfo.point.tag}<br/>Total Population: ${pointInfo.argumentText}M<br/>Population with Age over 60: ${pointInfo.valueText}M (${pointInfo.size}%)`,
19+
const customizeTooltip = (pointInfo: ChartTypes.BubblePointInfo): Record<string, string> => ({
20+
text: `${pointInfo.point?.tag}<br/>Total Population: ${pointInfo.argumentText}M<br/>Population with Age over 60: ${pointInfo.valueText}M (${pointInfo.size}%)`,
2121
});
2222

23-
function seriesClick(e: ChartTypes.SeriesClickEvent) {
23+
function seriesClick(e: ChartTypes.SeriesClickEvent): void {
2424
const series = e.target;
2525
if (series.isVisible()) {
2626
series.hide();
@@ -29,7 +29,7 @@ function seriesClick(e: ChartTypes.SeriesClickEvent) {
2929
}
3030
}
3131

32-
const customizeText = (e) => `${e.value}M`;
32+
const customizeText = (e: { value: string | number | Date }): string => `${e.value}M`;
3333

3434
function App() {
3535
return (

apps/demos/Demos/Charts/Bubble/ReactJs/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { dataSource } from './data.js';
1515

1616
const palette = ['#00ced1', '#008000', '#ffd700', '#ff7f50'];
1717
const customizeTooltip = (pointInfo) => ({
18-
text: `${pointInfo.point.tag}<br/>Total Population: ${pointInfo.argumentText}M<br/>Population with Age over 60: ${pointInfo.valueText}M (${pointInfo.size}%)`,
18+
text: `${pointInfo.point?.tag}<br/>Total Population: ${pointInfo.argumentText}M<br/>Population with Age over 60: ${pointInfo.valueText}M (${pointInfo.size}%)`,
1919
});
2020
function seriesClick(e) {
2121
const series = e.target;

0 commit comments

Comments
 (0)