Skip to content

Commit 830b3ed

Browse files
committed
Restrict return type further
1 parent 8716f51 commit 830b3ed

File tree

4 files changed

+43
-23
lines changed

4 files changed

+43
-23
lines changed

packages/react-debug-tools/src/ReactDebugHooks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ function useRef<T>(initialValue: T): {current: T} {
147147
}
148148

149149
function useLayoutEffect(
150-
create: () => mixed,
150+
create: () => (() => void) | void,
151151
inputs: Array<mixed> | void | null,
152152
): void {
153153
nextHook();
@@ -159,7 +159,7 @@ function useLayoutEffect(
159159
}
160160

161161
function useEffect(
162-
create: () => mixed,
162+
create: () => (() => void) | void,
163163
inputs: Array<mixed> | void | null,
164164
): void {
165165
nextHook();

packages/react-dom/src/server/ReactPartialRendererHooks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,8 @@ function useRef<T>(initialValue: T): {current: T} {
375375
}
376376

377377
export function useLayoutEffect(
378-
create: () => mixed,
379-
deps: Array<mixed> | void | null,
378+
create: () => (() => void) | void,
379+
inputs: Array<mixed> | void | null,
380380
) {
381381
if (__DEV__) {
382382
currentHookNameInDev = 'useLayoutEffect';

packages/react-reconciler/src/ReactFiberHooks.js

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,14 @@ export type Dispatcher = {
5959
observedBits: void | number | boolean,
6060
): T,
6161
useRef<T>(initialValue: T): {current: T},
62-
useEffect(create: () => mixed, deps: Array<mixed> | void | null): void,
63-
useLayoutEffect(create: () => mixed, deps: Array<mixed> | void | null): void,
62+
useEffect(
63+
create: () => (() => void) | void,
64+
deps: Array<mixed> | void | null,
65+
): void,
66+
useLayoutEffect(
67+
create: () => (() => void) | void,
68+
deps: Array<mixed> | void | null,
69+
): void,
6470
useCallback<T>(callback: T, deps: Array<mixed> | void | null): T,
6571
useMemo<T>(nextCreate: () => T, deps: Array<mixed> | void | null): T,
6672
useImperativeHandle<T>(
@@ -119,8 +125,8 @@ type HookDev = Hook & {
119125

120126
type Effect = {
121127
tag: HookEffectTag,
122-
create: () => mixed,
123-
destroy: (() => mixed) | null,
128+
create: () => (() => void) | void,
129+
destroy: (() => void) | null,
124130
deps: Array<mixed> | null,
125131
next: Effect,
126132
};
@@ -805,7 +811,7 @@ function updateEffectImpl(fiberEffectTag, hookEffectTag, create, deps): void {
805811
}
806812

807813
function mountEffect(
808-
create: () => mixed,
814+
create: () => (() => void) | void,
809815
deps: Array<mixed> | void | null,
810816
): void {
811817
return mountEffectImpl(
@@ -817,7 +823,7 @@ function mountEffect(
817823
}
818824

819825
function updateEffect(
820-
create: () => mixed,
826+
create: () => (() => void) | void,
821827
deps: Array<mixed> | void | null,
822828
): void {
823829
return updateEffectImpl(
@@ -829,7 +835,7 @@ function updateEffect(
829835
}
830836

831837
function mountLayoutEffect(
832-
create: () => mixed,
838+
create: () => (() => void) | void,
833839
deps: Array<mixed> | void | null,
834840
): void {
835841
return mountEffectImpl(
@@ -841,7 +847,7 @@ function mountLayoutEffect(
841847
}
842848

843849
function updateLayoutEffect(
844-
create: () => mixed,
850+
create: () => (() => void) | void,
845851
deps: Array<mixed> | void | null,
846852
): void {
847853
return updateEffectImpl(
@@ -860,7 +866,9 @@ function imperativeHandleEffect<T>(
860866
const refCallback = ref;
861867
const inst = create();
862868
refCallback(inst);
863-
return () => refCallback(null);
869+
return () => {
870+
refCallback(null);
871+
};
864872
} else if (ref !== null && ref !== undefined) {
865873
const refObject = ref;
866874
if (__DEV__) {
@@ -1205,7 +1213,10 @@ if (__DEV__) {
12051213
currentHookNameInDev = 'useContext';
12061214
return mountContext(context, observedBits);
12071215
},
1208-
useEffect(create: () => mixed, deps: Array<mixed> | void | null): void {
1216+
useEffect(
1217+
create: () => (() => void) | void,
1218+
deps: Array<mixed> | void | null,
1219+
): void {
12091220
currentHookNameInDev = 'useEffect';
12101221
return mountEffect(create, deps);
12111222
},
@@ -1218,7 +1229,7 @@ if (__DEV__) {
12181229
return mountImperativeHandle(ref, create, deps);
12191230
},
12201231
useLayoutEffect(
1221-
create: () => mixed,
1232+
create: () => (() => void) | void,
12221233
deps: Array<mixed> | void | null,
12231234
): void {
12241235
currentHookNameInDev = 'useLayoutEffect';
@@ -1289,7 +1300,10 @@ if (__DEV__) {
12891300
currentHookNameInDev = 'useContext';
12901301
return updateContext(context, observedBits);
12911302
},
1292-
useEffect(create: () => mixed, deps: Array<mixed> | void | null): void {
1303+
useEffect(
1304+
create: () => (() => void) | void,
1305+
deps: Array<mixed> | void | null,
1306+
): void {
12931307
currentHookNameInDev = 'useEffect';
12941308
return updateEffect(create, deps);
12951309
},
@@ -1302,7 +1316,7 @@ if (__DEV__) {
13021316
return updateImperativeHandle(ref, create, deps);
13031317
},
13041318
useLayoutEffect(
1305-
create: () => mixed,
1319+
create: () => (() => void) | void,
13061320
deps: Array<mixed> | void | null,
13071321
): void {
13081322
currentHookNameInDev = 'useLayoutEffect';
@@ -1376,7 +1390,10 @@ if (__DEV__) {
13761390
warnInvalidHookAccess();
13771391
return mountContext(context, observedBits);
13781392
},
1379-
useEffect(create: () => mixed, deps: Array<mixed> | void | null): void {
1393+
useEffect(
1394+
create: () => (() => void) | void,
1395+
deps: Array<mixed> | void | null,
1396+
): void {
13801397
currentHookNameInDev = 'useEffect';
13811398
warnInvalidHookAccess();
13821399
return mountEffect(create, deps);
@@ -1391,7 +1408,7 @@ if (__DEV__) {
13911408
return mountImperativeHandle(ref, create, deps);
13921409
},
13931410
useLayoutEffect(
1394-
create: () => mixed,
1411+
create: () => (() => void) | void,
13951412
deps: Array<mixed> | void | null,
13961413
): void {
13971414
currentHookNameInDev = 'useLayoutEffect';
@@ -1471,7 +1488,10 @@ if (__DEV__) {
14711488
warnInvalidHookAccess();
14721489
return updateContext(context, observedBits);
14731490
},
1474-
useEffect(create: () => mixed, deps: Array<mixed> | void | null): void {
1491+
useEffect(
1492+
create: () => (() => void) | void,
1493+
deps: Array<mixed> | void | null,
1494+
): void {
14751495
currentHookNameInDev = 'useEffect';
14761496
warnInvalidHookAccess();
14771497
return updateEffect(create, deps);
@@ -1486,7 +1506,7 @@ if (__DEV__) {
14861506
return updateImperativeHandle(ref, create, deps);
14871507
},
14881508
useLayoutEffect(
1489-
create: () => mixed,
1509+
create: () => (() => void) | void,
14901510
deps: Array<mixed> | void | null,
14911511
): void {
14921512
currentHookNameInDev = 'useLayoutEffect';

packages/react/src/ReactHooks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ export function useRef<T>(initialValue: T): {current: T} {
7171
}
7272

7373
export function useEffect(
74-
create: () => mixed,
74+
create: () => (() => void) | void,
7575
inputs: Array<mixed> | void | null,
7676
) {
7777
const dispatcher = resolveDispatcher();
7878
return dispatcher.useEffect(create, inputs);
7979
}
8080

8181
export function useLayoutEffect(
82-
create: () => mixed,
82+
create: () => (() => void) | void,
8383
inputs: Array<mixed> | void | null,
8484
) {
8585
const dispatcher = resolveDispatcher();

0 commit comments

Comments
 (0)