Skip to content

Commit 300ee3a

Browse files
jdpigeonclaude
andcommitted
Fix TypeScript types: canonical RootState containers, withRouter, History cleanup
- Rewrites withRouter HOC to use P extends object pattern (canonical RR v6 form) - Types mapStateToProps with RootState in all containers (Home, Design, Collect, Clean, Analyze) for proper state access typing - Provides nullable defaults (psdPlot, topoPlot, erpPlot, connectedDevice, params) at the container boundary so component props receive non-nullable values - Replaces `history: History` (react-router v5) with `{ push: (path) => void }` in all class component Props interfaces — components only use push - Documents connect()+withRouter inference limitation in routes.tsx comments - All 24 tests pass; typecheck clean; build succeeds Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent abe0d9e commit 300ee3a

File tree

12 files changed

+74
-37
lines changed

12 files changed

+74
-37
lines changed

src/renderer/components/CollectComponent/ConnectModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Observable } from 'rxjs';
22
import React, { Component } from 'react';
33
import { isNil, debounce } from 'lodash';
4-
import { History } from 'history';
4+
55
import {
66
DEVICES,
77
DEVICE_AVAILABILITY,
@@ -13,7 +13,7 @@ import { SignalQualityData } from '../../constants/interfaces';
1313
import { DeviceActions } from '../../actions';
1414

1515
interface Props {
16-
history: History;
16+
history: { push: (path: string) => void };
1717
open: boolean;
1818
onClose: () => void;
1919
connectedDevice: Record<string, any>;

src/renderer/components/CollectComponent/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Observable } from 'rxjs';
22
import React, { Component } from 'react';
3-
import { History } from 'history';
3+
44
import {
55
EXPERIMENTS,
66
DEVICES,
@@ -17,7 +17,7 @@ import RunComponent from './RunComponent';
1717
import { ExperimentActions, DeviceActions } from '../../actions';
1818

1919
export interface Props {
20-
history: History;
20+
history: { push: (path: string) => void };
2121
ExperimentActions: typeof ExperimentActions;
2222
connectedDevice: Record<string, any>;
2323
deviceType: DEVICES;

src/renderer/components/DesignComponent/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Component } from 'react';
2-
import { History } from 'history';
2+
33
import { isNil } from 'lodash';
44
import { toast } from 'react-toastify';
55
import styles from '../styles/common.module.css';
@@ -42,7 +42,7 @@ const DESIGN_STEPS = {
4242
};
4343

4444
export interface DesignProps {
45-
history: History;
45+
history: { push: (path: string) => void };
4646
type: EXPERIMENTS;
4747
title: string;
4848
params: ExperimentParameters;

src/renderer/components/EEGExplorationComponent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { Component } from 'react';
22
import { Observable } from 'rxjs';
3-
import { History } from 'history';
3+
44
import {
55
PLOTTING_INTERVAL,
66
CONNECTION_STATUS,
@@ -16,7 +16,7 @@ import { DeviceActions } from '../actions';
1616
import { SignalQualityData } from '../constants/interfaces';
1717

1818
interface Props {
19-
history: History;
19+
history: { push: (path: string) => void };
2020
connectedDevice: Record<string, any>;
2121
signalQualityObservable?: Observable<SignalQualityData>;
2222
deviceType: DEVICES;

src/renderer/components/HomeComponent/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { isNil } from 'lodash';
33
import { toast } from 'react-toastify';
44
import dayjs from 'dayjs';
55
import relativeTime from 'dayjs/plugin/relativeTime';
6-
import { History } from 'history';
6+
77

88
dayjs.extend(relativeTime);
99
import { Observable } from 'rxjs';
@@ -60,7 +60,7 @@ export interface Props {
6060
deviceAvailability: DEVICE_AVAILABILITY;
6161
deviceType: DEVICES;
6262
ExperimentActions: typeof ExperimentActions;
63-
history: History;
63+
history: { push: (path: string) => void };
6464
PyodideActions: typeof PyodideActions;
6565
signalQualityObservable?: Observable<SignalQualityData>;
6666
topoPlot: {

src/renderer/containers/AnalyzeContainer.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@ import { bindActionCreators } from 'redux';
22
import { connect } from 'react-redux';
33
import Analyze from '../components/AnalyzeComponent';
44
import { PyodideActions, ExperimentActions } from '../actions';
5+
import { RootState } from '../reducers';
56

6-
function mapStateToProps(state) {
7+
function mapStateToProps(state: RootState) {
78
return {
89
title: state.experiment.title,
910
type: state.experiment.type,
1011
deviceType: state.device.deviceType,
1112
isEEGEnabled: state.experiment.isEEGEnabled,
12-
...state.pyodide,
13+
epochsInfo: state.pyodide.epochsInfo,
14+
channelInfo: state.pyodide.channelInfo,
15+
// Provide empty-object defaults: component expects non-nullable records
16+
psdPlot: state.pyodide.psdPlot ?? {},
17+
topoPlot: state.pyodide.topoPlot ?? {},
18+
erpPlot: state.pyodide.erpPlot ?? {},
19+
worker: state.pyodide.worker,
1320
};
1421
}
1522

src/renderer/containers/CleanContainer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ import { bindActionCreators } from 'redux';
22
import { connect } from 'react-redux';
33
import CleanComponent from '../components/CleanComponent';
44
import { PyodideActions, ExperimentActions } from '../actions';
5+
import { RootState } from '../reducers';
56

6-
function mapStateToProps(state) {
7+
function mapStateToProps(state: RootState) {
78
return {
89
type: state.experiment.type,
910
title: state.experiment.title,
1011
subject: state.experiment.subject,
1112
group: state.experiment.group,
1213
session: state.experiment.session,
1314
deviceType: state.device.deviceType,
14-
...state.pyodide,
15+
epochsInfo: state.pyodide.epochsInfo,
1516
};
1617
}
1718

src/renderer/containers/CollectContainer.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@ import { connect } from 'react-redux';
33
import Collect from '../components/CollectComponent';
44
import { DeviceActions, ExperimentActions } from '../actions';
55
import { withRouter } from '../utils/withRouter';
6+
import { RootState } from '../reducers';
67

7-
function mapStateToProps(state) {
8+
function mapStateToProps(state: RootState) {
89
return {
910
...state.device,
11+
connectedDevice: state.device.connectedDevice ?? {},
12+
rawObservable: state.device.rawObservable ?? undefined,
13+
signalQualityObservable:
14+
state.device.signalQualityObservable ?? (undefined as any),
1015
...state.experiment,
16+
params: state.experiment.params ?? ({} as any),
1117
};
1218
}
1319

@@ -18,4 +24,6 @@ function mapDispatchToProps(dispatch) {
1824
};
1925
}
2026

21-
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Collect) as any);
27+
export default withRouter(
28+
connect(mapStateToProps, mapDispatchToProps)(Collect)
29+
);

src/renderer/containers/ExperimentDesignContainer.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ import { connect } from 'react-redux';
33
import Design from '../components/DesignComponent';
44
import { ExperimentActions } from '../actions';
55
import { withRouter } from '../utils/withRouter';
6+
import { RootState } from '../reducers';
67

7-
function mapStateToProps(state) {
8+
function mapStateToProps(state: RootState) {
89
return {
910
...state.experiment,
11+
// provide empty-object default: DesignProps.params is non-nullable
12+
params: state.experiment.params ?? ({} as any),
1013
};
1114
}
1215

@@ -16,4 +19,4 @@ function mapDispatchToProps(dispatch) {
1619
};
1720
}
1821

19-
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Design) as any);
22+
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Design));

src/renderer/containers/HomeContainer.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@ import { bindActionCreators } from 'redux';
33
import Home from '../components/HomeComponent';
44
import { DeviceActions, ExperimentActions, PyodideActions } from '../actions';
55
import { withRouter } from '../utils/withRouter';
6+
import { RootState } from '../reducers';
67

7-
function mapStateToProps(state) {
8+
function mapStateToProps(state: RootState) {
89
return {
910
...state.device,
10-
...state.pyodide,
11+
connectedDevice: state.device.connectedDevice ?? {},
12+
rawObservable: state.device.rawObservable ?? undefined,
13+
signalQualityObservable: state.device.signalQualityObservable ?? undefined,
14+
// Pyodide state with nullable defaults
15+
epochsInfo: state.pyodide.epochsInfo,
16+
channelInfo: state.pyodide.channelInfo,
17+
psdPlot: state.pyodide.psdPlot ?? {},
18+
topoPlot: state.pyodide.topoPlot ?? {},
19+
erpPlot: state.pyodide.erpPlot ?? {},
20+
worker: state.pyodide.worker,
1121
};
1222
}
1323

@@ -19,4 +29,4 @@ function mapDispatchToProps(dispatch) {
1929
};
2030
}
2131

22-
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Home) as any);
32+
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Home));

0 commit comments

Comments
 (0)