Skip to content

Commit 642c460

Browse files
committed
chore: improve types in components
1 parent 0867241 commit 642c460

26 files changed

Lines changed: 87 additions & 76 deletions

src/component/EventsTrackers/KeysListenerTracker.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,9 @@ function KeysListenerTracker(props: KeysListenerTrackerProps) {
279279
);
280280

281281
const keysPreferencesListenerHandler = useCallback(
282-
(e: any, num: any) => {
282+
(event: globalThis.KeyboardEvent, num: number) => {
283283
if (data && data.length > 0 && num >= 1 && num <= 9) {
284-
if (e.shiftKey) {
284+
if (event.shiftKey) {
285285
dispatch({
286286
type: 'SET_KEY_PREFERENCES',
287287
payload: {
@@ -291,7 +291,7 @@ function KeysListenerTracker(props: KeysListenerTrackerProps) {
291291
toaster.show({
292292
message: `Configuration Reset, press '${num}' again to reload it.`,
293293
});
294-
} else if (!checkModifierKeyActivated(e)) {
294+
} else if (!checkModifierKeyActivated(event)) {
295295
if (keysPreferences?.[num]) {
296296
dispatch({
297297
type: 'APPLY_KEY_PREFERENCES',
@@ -317,7 +317,7 @@ function KeysListenerTracker(props: KeysListenerTrackerProps) {
317317
);
318318

319319
const toolsListenerHandler = useCallback(
320-
(e: any) => {
320+
(e: globalThis.KeyboardEvent) => {
321321
try {
322322
if (!e.shiftKey && !e.metaKey && !e.ctrlKey) {
323323
switch (e.key) {
@@ -495,19 +495,19 @@ function KeysListenerTracker(props: KeysListenerTrackerProps) {
495495
);
496496

497497
const handleOnKeyDown = useCallback(
498-
(e: any) => {
499-
if (!ignoreElement(e) && mouseIsOverDisplayer.current) {
500-
const num = Number(e.code.slice(-1)) || 0;
498+
(event: globalThis.KeyboardEvent) => {
499+
if (!ignoreElement(event) && mouseIsOverDisplayer.current) {
500+
const num = Number(event.code.slice(-1)) || 0;
501501
if (num > 0) {
502-
keysPreferencesListenerHandler(e, num);
502+
keysPreferencesListenerHandler(event, num);
503503
} else if (
504-
['Delete', 'Backspace'].includes(e.key) &&
504+
['Delete', 'Backspace'].includes(event.key) &&
505505
highlight.sourceData
506506
) {
507-
e.preventDefault();
507+
event.preventDefault();
508508
void deleteHandler(highlight.sourceData);
509509
} else {
510-
toolsListenerHandler(e);
510+
toolsListenerHandler(event);
511511
}
512512
}
513513
},
@@ -532,7 +532,7 @@ function KeysListenerTracker(props: KeysListenerTrackerProps) {
532532
const tags = new Set(['INPUT', 'TEXTAREA']);
533533
const inputTypes = new Set(['checkbox', 'radio']);
534534

535-
function ignoreElement(e: Event) {
535+
function ignoreElement(e: globalThis.KeyboardEvent) {
536536
const element = e.target as HTMLInputElement;
537537
return (
538538
(tags.has(element.tagName) && !inputTypes.has(element.type)) ||

src/component/EventsTrackers/MouseTracker.tsx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CSSProperties, ReactNode } from 'react';
1+
import type { CSSProperties, MouseEvent, ReactNode } from 'react';
22
import { createContext, useCallback, useContext, useState } from 'react';
33

44
interface MouseTrackerData {
@@ -23,32 +23,28 @@ interface MouseTrackerProps {
2323
noPropagation?: boolean;
2424
}
2525

26-
export function MouseTracker({
27-
children,
28-
className,
29-
style,
30-
noPropagation,
31-
}: MouseTrackerProps) {
26+
export function MouseTracker(props: MouseTrackerProps) {
27+
const { children, className, style, noPropagation } = props;
3228
const [mouseTrackerState, setMouseTrackerState] =
3329
useState<MouseTrackerData | null>(null);
3430
const mouseMoveHandler = useCallback(
35-
(e: any) => {
36-
const boundingRect = e.currentTarget.getBoundingClientRect();
37-
const x = e.clientX - boundingRect.x;
38-
const y = e.clientY - boundingRect.y;
31+
(event: MouseEvent) => {
32+
const boundingRect = event.currentTarget.getBoundingClientRect();
33+
const x = event.clientX - boundingRect.x;
34+
const y = event.clientY - boundingRect.y;
3935
setMouseTrackerState({ x, y });
4036
if (noPropagation) {
41-
e.stopPropagation();
37+
event.stopPropagation();
4238
}
4339
},
4440
[noPropagation],
4541
);
4642

4743
const mouseLeaveHandler = useCallback(
48-
(e: any) => {
44+
(event: MouseEvent) => {
4945
setMouseTrackerState(null);
5046
if (noPropagation) {
51-
e.stopPropagation();
47+
event.stopPropagation();
5248
}
5349
},
5450
[noPropagation],

src/component/assignment/utilities/getAssignments.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function setZonesAssignments(assignments: Assignments, zones: Zones) {
5555

5656
function setAssignment(
5757
assignments: Assignments,
58-
id: any,
58+
id: string,
5959
axis: Axis,
6060
diaID: string,
6161
) {

src/component/elements/Button.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
CSSProperties,
88
ComponentPropsWithoutRef,
99
ElementType,
10+
MouseEvent,
1011
} from 'react';
1112
import { FaInfoCircle } from 'react-icons/fa';
1213

@@ -285,7 +286,7 @@ function Button<E extends ElementType = 'button'>(props: ButtonProps<E>) {
285286
onClick={
286287
Wrapper === 'button' || (Wrapper === 'div' && !disabled)
287288
? onClick
288-
: (e: any) => e.stopPropagation()
289+
: (e: MouseEvent) => e.stopPropagation()
289290
}
290291
css={[
291292
styles.button({

src/component/elements/D3Axis.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ interface D3AxisProps
2727
BaseD3AxisProps,
2828
Pick<SVGAttributes<SVGGElement>, 'transform' | 'children' | 'className'>,
2929
UseLinearPrimaryTicksResult {
30-
gridSize?: number;
30+
gridSize: number;
3131
primaryGridProps?: PrimaryGridElementProps;
3232
secondaryGridProps?: SecondaryGridElementProps;
3333
showGrid?: boolean;
@@ -41,7 +41,7 @@ interface BaseLineProps
4141

4242
interface GridProps<T> extends UseLinearPrimaryTicksResult {
4343
axisPosition: AxisPosition;
44-
gridSize?: number;
44+
gridSize: number;
4545
gridProps?: T;
4646
}
4747

@@ -160,7 +160,11 @@ function getSecondaryTickOffset(ticks: Array<Tick<number>>, direction: -1 | 1) {
160160
return (second.position - first.position) / 2;
161161
}
162162

163-
function getLinePosition(position: any, axisPosition: any, gridSize: any) {
163+
function getLinePosition(
164+
position: number,
165+
axisPosition: AxisPosition,
166+
gridSize: number,
167+
) {
164168
if (['top', 'bottom'].includes(axisPosition)) {
165169
return {
166170
x1: position,

src/component/elements/MoleculeSelection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export default function MoleculeSelection(props: MoleculeSelectionProps) {
8282
}, [index, molecules]);
8383

8484
const onChangeHandler = useCallback(
85-
(slideIndex: any) => {
85+
(slideIndex: number) => {
8686
setCurrentIndex(slideIndex);
8787
onChange(slideIndex);
8888
},

src/component/elements/dropDownButton/DropDownButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function DropDownButton<T extends DropDownListItem>(
5252
}
5353
}, [selectedKey, data]);
5454

55-
function selectHandler(index: any) {
55+
function selectHandler(index: number) {
5656
setOpen(false);
5757
setItem(data[index]);
5858
onSelect?.(data[index]);

src/component/elements/export/units.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function convert(
4949
value: number,
5050
fromUnit: Unit,
5151
toUnit: Unit,
52-
dpi: any,
52+
dpi: number,
5353
options: ConvertOptions = {},
5454
): number {
5555
const { precision } = options;

src/component/elements/export/useExportConfigurer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function useExportConfigurer(options: ExportSettings) {
2929
return value;
3030
}
3131

32-
function changeDPI(value: any) {
32+
function changeDPI(value: number) {
3333
const { width, height, dpi } = refSize.current;
3434
const convertedWidth =
3535
convertToPixels(width, unit, 1, { precision: 2 }) * value;

src/component/hooks/useSVGUnitConverter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useMemo } from 'react';
22

33
import { useChartData } from '../context/ChartContext.js';
44

5-
function truncate(value: any, numberOfDigits = 0) {
5+
function truncate(value: number, numberOfDigits = 0) {
66
const power = 10 ** numberOfDigits;
77
return Math.trunc(value * power) / power;
88
}

0 commit comments

Comments
 (0)