From a978e525a59f4f02a99fb4913ed7e802ee99311b Mon Sep 17 00:00:00 2001 From: Theodore Gregory <5040901+tjmgregory@users.noreply.github.com> Date: Wed, 24 Aug 2022 18:03:30 +0100 Subject: [PATCH] fix: corrects the type for `act` Corrects for the addition of returned values from the act function: https://github.com/facebook/react/pull/21759 --- types/react-dom/test-utils/index.d.ts | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/types/react-dom/test-utils/index.d.ts b/types/react-dom/test-utils/index.d.ts index 567dcf31c9ec3a..e82e41c368b30b 100644 --- a/types/react-dom/test-utils/index.d.ts +++ b/types/react-dom/test-utils/index.d.ts @@ -281,23 +281,16 @@ export function createRenderer(): ShallowRenderer; * Wrap any code rendering and triggering updates to your components into `act()` calls. * * Ensures that the behavior in your tests matches what happens in the browser - * more closely by executing pending `useEffect`s before returning. This also - * reduces the amount of re-renders done. + * more closely by executing pending `useEffect`s before returning. + * + * All `useEffect`s scheduled by the actions within the callback will be condensed into + * a single action, with only the latest values returned, to improve the efficiency of the test. * - * @param callback A synchronous, void callback that will execute as a single, complete React commit. + * @param callback A synchronous or asyncronous callback that will execute as a single, complete React commit. * * @see https://reactjs.org/blog/2019/02/06/react-v16.8.0.html#testing-hooks */ -// NOTES -// - the order of these signatures matters - typescript will check the signatures in source order. -// If the `() => VoidOrUndefinedOnly` signature is first, it'll erroneously match a Promise returning function for users with -// `strictNullChecks: false`. -// - VoidOrUndefinedOnly is there to forbid any non-void return values for users with `strictNullChecks: true` -declare const UNDEFINED_VOID_ONLY: unique symbol; -// tslint:disable-next-line: void-return -type VoidOrUndefinedOnly = void | { [UNDEFINED_VOID_ONLY]: never }; -export function act(callback: () => Promise): Promise; -export function act(callback: () => VoidOrUndefinedOnly): void; +export function act(callback: () => Promise | T): Promise; // Intentionally doesn't extend PromiseLike. // Ideally this should be as hard to accidentally use as possible.