Skip to content

Commit 406ee02

Browse files
committed
Preparing for React 18: useCallback will no longer be typed as any
1 parent 0b2c8de commit 406ee02

File tree

8 files changed

+34
-29
lines changed

8 files changed

+34
-29
lines changed

ui/frontend/AdvancedOptionsMenu.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const AdvancedOptionsMenu: React.FC = () => {
1616

1717
const dispatch = useDispatch();
1818

19-
const changeEdition = useCallback((e) => dispatch(actions.changeEdition(e)), [dispatch]);
20-
const changeBacktrace = useCallback((b) => dispatch(actions.changeBacktrace(b)), [dispatch]);
19+
const changeEdition = useCallback((e: Edition) => dispatch(actions.changeEdition(e)), [dispatch]);
20+
const changeBacktrace = useCallback((b: Backtrace) => dispatch(actions.changeBacktrace(b)), [dispatch]);
2121

2222
return (
2323
<MenuGroup title="Advanced options">

ui/frontend/ChannelMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const ChannelMenu: React.FC<ChannelMenuProps> = props => {
2424
const nightlyVersionDetails = useSelector(selectors.nightlyVersionDetailsText);
2525

2626
const dispatch = useDispatch();
27-
const changeChannel = useCallback((channel) => {
27+
const changeChannel = useCallback((channel: Channel) => {
2828
dispatch(actions.changeChannel(channel));
2929
props.close();
3030
}, [dispatch, props]);

ui/frontend/ConfigElement.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,47 @@ import MenuItem from './MenuItem';
44

55
import styles from './ConfigElement.module.css';
66

7-
interface EitherProps extends ConfigElementProps {
7+
interface EitherProps<T extends string> extends ConfigElementProps {
88
id: string;
99
a: string;
1010
b: string;
1111
aLabel?: string;
1212
bLabel?: string;
13-
value: string;
14-
onChange: (_: string) => any;
13+
value: T;
14+
onChange: (_: T) => any;
1515
}
1616

17-
export const Either: React.FC<EitherProps> =
18-
({ id, a, b, aLabel = a, bLabel = b, value, onChange, ...rest }) => (
17+
export const Either =
18+
<T extends string,>({ id, a, b, aLabel = a, bLabel = b, value, onChange, ...rest }: EitherProps<T>) => (
1919
<ConfigElement {...rest}>
2020
<div className={styles.toggle}>
2121
<input id={`${id}-a`}
2222
name={id}
2323
value={a}
2424
type="radio"
2525
checked={value === a}
26-
onChange={() => onChange(a)} />
26+
onChange={() => onChange(a as T)} />
2727
<label htmlFor={`${id}-a`}>{aLabel}</label>
2828
<input id={`${id}-b`}
2929
name={id}
3030
value={b}
3131
type="radio"
3232
checked={value === b}
33-
onChange={() => onChange(b)} />
33+
onChange={() => onChange(b as T)} />
3434
<label htmlFor={`${id}-b`}>{bLabel}</label>
3535
</div>
3636
</ConfigElement>
3737
);
3838

39-
interface SelectProps extends ConfigElementProps {
40-
value: string;
41-
onChange: (_: string) => any;
39+
interface SelectProps<T extends string> extends ConfigElementProps {
40+
children: React.ReactNode;
41+
value: T;
42+
onChange: (_: T) => any;
4243
}
4344

44-
export const Select: React.FC<SelectProps> = ({ value, onChange, children, ...rest }) => (
45+
export const Select = <T extends string,>({ value, onChange, children, ...rest }: SelectProps<T>) => (
4546
<ConfigElement {...rest}>
46-
<select className={styles.select} value={value} onChange={e => onChange(e.target.value)}>
47+
<select className={styles.select} value={value} onChange={e => onChange(e.target.value as T)}>
4748
{children}
4849
</select>
4950
</ConfigElement>

ui/frontend/ConfigMenu.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,19 @@ const ConfigMenu: React.FC<ConfigMenuProps> = () => {
3737
const processAssembly = useSelector((state: State) => state.configuration.processAssembly);
3838

3939
const dispatch = useDispatch();
40-
const changeAceTheme = useCallback((t) => dispatch(actions.changeAceTheme(t)), [dispatch]);
41-
const changeMonacoTheme = useCallback((t) => dispatch(actions.changeMonacoTheme(t)), [dispatch]);
42-
const changeKeybinding = useCallback((k) => dispatch(actions.changeKeybinding(k)), [dispatch]);
43-
const changeOrientation = useCallback((o) => dispatch(actions.changeOrientation(o)), [dispatch]);
44-
const changeEditorStyle = useCallback((e) => dispatch(actions.changeEditor(e)), [dispatch]);
45-
const changeAssemblyFlavor = useCallback((a) => dispatch(actions.changeAssemblyFlavor(a)), [dispatch]);
46-
const changePairCharacters = useCallback((p) => dispatch(actions.changePairCharacters(p)), [dispatch]);
47-
const changeProcessAssembly = useCallback((p) => dispatch(actions.changeProcessAssembly(p)), [dispatch]);
48-
const changeDemangleAssembly = useCallback((d) => dispatch(actions.changeDemangleAssembly(d)), [dispatch]);
40+
const changeAceTheme = useCallback((t: string) => dispatch(actions.changeAceTheme(t)), [dispatch]);
41+
const changeMonacoTheme = useCallback((t: string) => dispatch(actions.changeMonacoTheme(t)), [dispatch]);
42+
const changeKeybinding = useCallback((k: string) => dispatch(actions.changeKeybinding(k)), [dispatch]);
43+
const changeOrientation = useCallback((o: Orientation) => dispatch(actions.changeOrientation(o)), [dispatch]);
44+
const changeEditorStyle = useCallback((e: Editor) => dispatch(actions.changeEditor(e)), [dispatch]);
45+
const changeAssemblyFlavor =
46+
useCallback((a: AssemblyFlavor) => dispatch(actions.changeAssemblyFlavor(a)), [dispatch]);
47+
const changePairCharacters =
48+
useCallback((p: PairCharacters) => dispatch(actions.changePairCharacters(p)), [dispatch]);
49+
const changeProcessAssembly =
50+
useCallback((p: ProcessAssembly) => dispatch(actions.changeProcessAssembly(p)), [dispatch]);
51+
const changeDemangleAssembly =
52+
useCallback((d: DemangleAssembly) => dispatch(actions.changeDemangleAssembly(d)), [dispatch]);
4953

5054
return (
5155
<Fragment>

ui/frontend/ModeMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface ModeMenuProps {
1515
const ModeMenu: React.FC<ModeMenuProps> = props => {
1616
const mode = useSelector((state: State) => state.configuration.mode);
1717
const dispatch = useDispatch();
18-
const changeMode = useCallback((mode) => {
18+
const changeMode = useCallback((mode: Mode) => {
1919
dispatch(actions.changeMode(mode));
2020
props.close();
2121
}, [dispatch, props]

ui/frontend/editor/AceEditor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ const AceEditor: React.FC<AceEditorProps> = props => {
200200
const previouslyNotified = useRef<string[]>([]);
201201
const onEditCodeDebounced = useRafDebouncedFunction(
202202
props.onEditCode,
203-
useCallback(code => previouslyNotified.current.push(code), [previouslyNotified]),
203+
useCallback((code: string) => previouslyNotified.current.push(code), [previouslyNotified]),
204204
);
205205

206206
useEditorProp(editor, onEditCodeDebounced, useCallback((editor, onEditCode) => {

ui/frontend/editor/Editor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ const Editor: React.FC = () => {
125125

126126
const dispatch = useAppDispatch();
127127
const execute = useCallback(() => dispatch(actions.performPrimaryAction()), [dispatch]);
128-
const onEditCode = useCallback((c) => dispatch(actions.editCode(c)), [dispatch]);
128+
const onEditCode = useCallback((c: string) => dispatch(actions.editCode(c)), [dispatch]);
129129

130130
const SelectedEditor = editorMap[editor];
131131

ui/frontend/uss-router/Link.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useContext, useCallback } from 'react';
1+
import React, { useContext, useCallback, MouseEventHandler } from 'react';
22
import { useDispatch } from 'react-redux';
33

44
import { Context } from './Router';
@@ -16,7 +16,7 @@ const Link: React.FC<LinkProps> = (props) => {
1616
const router = useContext(Context);
1717
const { action, onClick, children, ...anchorProps } = props;
1818

19-
const realOnClick = useCallback(e => {
19+
const realOnClick: MouseEventHandler<HTMLAnchorElement> = useCallback((e) => {
2020
if (onClick) {
2121
onClick();
2222
} else if (action) {

0 commit comments

Comments
 (0)