Skip to content

Commit da96bd3

Browse files
committed
fix typing and upgrade errors
1 parent e015b1a commit da96bd3

File tree

27 files changed

+133
-122
lines changed

27 files changed

+133
-122
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"postlint-styles-fix": "prettier --single-quote --write '**/*.{css,scss}'",
2525
"test": "cross-env jest --passWithNoTests",
2626
"test-all": "npm run lint && npm run lint-styles && npm run typecheck && npm run build && npm test",
27+
"tsc": "tsc --noEmit",
2728
"typecheck": "tsc --noEmit"
2829
},
2930
"lint-staged": {

src/renderer/components/AnalyzeComponent.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from 'semantic-ui-react';
1414
import { isNil, isArray, isString } from 'lodash';
1515
import Plot from 'react-plotly.js';
16+
import type { Data as PlotlyData } from 'plotly.js';
1617
import styles from './styles/common.module.css';
1718
import {
1819
DEVICES,
@@ -95,7 +96,7 @@ interface State {
9596
// TODO: implement outlier display toggle
9697
// displayOutlierVisible: boolean;
9798
displayMode: string;
98-
dataToPlot: number[];
99+
dataToPlot: PlotlyData[];
99100
layout: Record<string, any>;
100101
helpMode: string;
101102
dependentVariables: Array<{
@@ -118,7 +119,7 @@ export default class Analyze extends Component<Props, State> {
118119
eegFilePaths: [{ key: '', text: '', value: { name: '', dir: '' } }],
119120
behaviorFilePaths: [{ key: '', text: '', value: '' }],
120121
dependentVariables: [{ key: '', text: '', value: '' }],
121-
dataToPlot: [],
122+
dataToPlot: [] as PlotlyData[],
122123
layout: {},
123124
selectedDependentVariable: '',
124125
removeOutliers: true,

src/renderer/components/CleanComponent/index.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,17 @@ export default class Clean extends Component<Props, State> {
9595
}
9696

9797
handleRecordingChange(event: Record<string, any>, data: DropdownProps) {
98-
if (isArray(data.value)) {
99-
const filePaths = data.value.filter<string>(isString);
98+
const { value } = data;
99+
if (isArray(value)) {
100+
const filePaths = (value as (string | number | boolean)[]).filter(isString) as string[];
100101
this.setState({ selectedFilePaths: filePaths });
101102
}
102103
}
103104

104105
handleSubjectChange(event: Record<string, any>, data: DropdownProps) {
105-
if (!isNil(data) && isString(data.value)) {
106-
this.setState({ selectedSubject: data.value, selectedFilePaths: [] });
106+
const { value } = data;
107+
if (!isNil(data) && isString(value)) {
108+
this.setState({ selectedSubject: value as string, selectedFilePaths: [] });
107109
}
108110
}
109111

@@ -143,7 +145,7 @@ export default class Clean extends Component<Props, State> {
143145
(infoObj) => infoObj.name === 'Drop Percentage'
144146
)?.value;
145147

146-
if (drop && drop >= 2) {
148+
if (drop && typeof drop === 'number' && drop >= 2) {
147149
return (
148150
<Link to="/analyze">
149151
<Button primary>Analyze Dataset</Button>
@@ -208,10 +210,12 @@ export default class Clean extends Component<Props, State> {
208210
closeOnChange
209211
value={this.state.selectedFilePaths}
210212
options={this.state.eegFilePaths.filter((filepath) => {
211-
if (isString(filepath.value)) {
212-
const subjectFromFilepath = filepath.value.split(
213+
const val = filepath.value;
214+
if (isString(val)) {
215+
const strVal = val as string;
216+
const subjectFromFilepath = strVal.split(
213217
path.sep
214-
)[filepath.value.split(path.sep).length - 3];
218+
)[strVal.split(path.sep).length - 3];
215219
return (
216220
this.state.selectedSubject === subjectFromFilepath
217221
);
@@ -231,7 +235,7 @@ export default class Clean extends Component<Props, State> {
231235
<Button
232236
primary
233237
disabled={isNil(this.props.epochsInfo)}
234-
onClick={this.props.PyodideActions.CleanEpochs}
238+
onClick={() => this.props.PyodideActions.CleanEpochs()}
235239
>
236240
Clean Data
237241
</Button>

src/renderer/components/CollectComponent/ConnectModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export default class ConnectModal extends Component<Props, State> {
160160
<Modal.Content>
161161
<Grid textAlign="center" columns="equal">
162162
<Grid.Column>
163-
{this.state.instructionProgress !== 0 && (
163+
{(this.state.instructionProgress as number) !== 0 && (
164164
<Button
165165
fluid
166166
className={styles.secondaryButton}

src/renderer/components/DesignComponent/CustomDesignComponent.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,11 @@ export default class CustomDesign extends Component<DesignProps, State> {
148148
value={this.state.params.description?.question}
149149
placeholder="Explain your research question here."
150150
onChange={(event, data) => {
151-
if (!isString(data.value)) {
151+
const val = data.value;
152+
if (!isString(val)) {
152153
return;
153154
}
154-
this.handleSetText(data.value, 'question');
155+
this.handleSetText(val as string, 'question');
155156
}}
156157
/>
157158
</Form>
@@ -172,10 +173,11 @@ export default class CustomDesign extends Component<DesignProps, State> {
172173
value={this.state.params.description?.hypothesis}
173174
placeholder="Describe your hypothesis here."
174175
onChange={(event, data) => {
175-
if (!isString(data.value)) {
176+
const val = data.value;
177+
if (!isString(val)) {
176178
return;
177179
}
178-
this.handleSetText(data.value, 'hypothesis');
180+
this.handleSetText(val as string, 'hypothesis');
179181
}}
180182
/>
181183
</Form>
@@ -196,10 +198,11 @@ export default class CustomDesign extends Component<DesignProps, State> {
196198
value={this.state.params.description?.methods}
197199
placeholder="Explain how you will design your experiment to answer the question here."
198200
onChange={(event, data) => {
199-
if (!isString(data.value)) {
201+
const val = data.value;
202+
if (!isString(val)) {
200203
return;
201204
}
202-
this.handleSetText(data.value, 'methods');
205+
this.handleSetText(val as string, 'methods');
203206
}}
204207
/>
205208
</Form>
@@ -563,11 +566,12 @@ export default class CustomDesign extends Component<DesignProps, State> {
563566
value={this.state.params.intro}
564567
placeholder="e.g., You will view a series of faces and houses. Press 1 when a face appears and 9 for a house. Press the the space bar on your keyboard to start doing the practice trials. If you want to skip the practice trials and go directly to the task, press the 'q' button on your keyboard."
565568
onChange={(event, data) => {
566-
if (!isString(data.value)) {
569+
const val = data.value;
570+
if (!isString(val)) {
567571
return;
568572
}
569573
this.setState({
570-
params: { ...this.state.params, intro: data.value },
574+
params: { ...this.state.params, intro: val as string },
571575
saved: false,
572576
});
573577
}}
@@ -593,11 +597,12 @@ export default class CustomDesign extends Component<DesignProps, State> {
593597
value={this.state.params.taskHelp}
594598
placeholder="e.g., Press 1 for a face and 9 for a house"
595599
onChange={(event, data) => {
596-
if (!isString(data.value)) {
600+
const val = data.value;
601+
if (!isString(val)) {
597602
return;
598603
}
599604
this.setState({
600-
params: { ...this.state.params, taskHelp: data.value },
605+
params: { ...this.state.params, taskHelp: val as string },
601606
saved: false,
602607
});
603608
}}

src/renderer/components/DesignComponent/StimuliDesignColumn.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default class StimuliDesignColumn extends Component<Props, State> {
5353
async handleSelectFolder() {
5454
const dir = await loadFromSystemDialog(FILE_TYPES.STIMULUS_DIR);
5555
if (dir && isString(dir)) {
56-
const images = readImages(dir);
56+
const images = await readImages(dir);
5757
if (images.length < 1) {
5858
toast.error('No images in folder!');
5959
}
@@ -97,10 +97,11 @@ export default class StimuliDesignColumn extends Component<Props, State> {
9797
selection
9898
value={this.props.response}
9999
onChange={(event, data) => {
100-
if (data.value && isString(data.value)) {
100+
const val = data.value;
101+
if (val && isString(val)) {
101102
this.props.onChange(
102103
'response',
103-
data.value,
104+
val as string,
104105
`stimulus${this.props.num}`
105106
);
106107
}

src/renderer/components/DesignComponent/StimuliRow.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ export const StimuliRow: React.FC<Props> = ({
4848
fluid
4949
selection
5050
value={response}
51-
onChange={(event, data) =>
52-
onChange(num, 'response', isString(data.value) ? data.value : '')
53-
}
51+
onChange={(event, data) => {
52+
const val = data.value;
53+
onChange(num, 'response', isString(val) ? (val as string) : '');
54+
}}
5455
placeholder="Response"
5556
options={RESPONSE_OPTIONS}
5657
/>

src/renderer/components/DesignComponent/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ export default class Design extends Component<DesignProps, State> {
8686
this.handleEEGEnabled = this.handleEEGEnabled.bind(this);
8787
}
8888

89-
componentDidMount() {
90-
this.setState({ recentWorkspaces: readWorkspaces() });
89+
async componentDidMount() {
90+
this.setState({ recentWorkspaces: await readWorkspaces() });
9191
}
9292

9393
handleStepClick(step: string) {

src/renderer/components/ExperimentWindow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const ExperimentWindow: React.FC<ExperimentWindowProps> = ({
3030
const experimentClone = clonedeep(experimentObject);
3131
const paramsClone = clonedeep(params);
3232
experimentClone.parameters = paramsClone;
33-
const experimentToRun = lab.util.fromObject(experimentClone, lab);
33+
const experimentToRun = lab.core.deserialize(experimentClone, lab);
3434

3535
experimentToRun.parameters.title = title;
3636
if (params.stimuli) {

src/renderer/components/HomeComponent/OverviewComponent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const OverviewComponent: React.FC<Props> = ({
8989
};
9090

9191
// Generic curreid enum type guard
92-
function isEnum<T>(en: T) {
92+
function isEnum<T extends object>(en: T) {
9393
return (val: any): val is T[keyof T] => val in Object.values(en);
9494
}
9595

0 commit comments

Comments
 (0)