Skip to content

Commit b7ba850

Browse files
committed
react: Update types for changes declared in the CHANGELOG
facebook/react#16254
1 parent c15bcd2 commit b7ba850

File tree

4 files changed

+45
-17
lines changed

4 files changed

+45
-17
lines changed

types/react-test-renderer/index.d.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Type definitions for react-test-renderer 16.8
1+
// Type definitions for react-test-renderer 16.9
22
// Project: https://facebook.github.io/react/
33
// Definitions by: Arvitaly <https://github.com/arvitaly>
44
// Lochbrunner <https://github.com/lochbrunner>
@@ -53,6 +53,20 @@ export interface TestRendererOptions {
5353
}
5454
export function create(nextElement: ReactElement, options?: TestRendererOptions): ReactTestRenderer;
5555

56+
/**
57+
* Wrap any code rendering and triggering updates to your components into `act()` calls.
58+
*
59+
* Ensures that the behavior in your tests matches what happens in the browser
60+
* more closely by executing pending `useEffect`s before returning. This also
61+
* reduces the amount of re-renders done.
62+
*
63+
* @param callback An asynchronous, void callback that will execute as a single, complete React commit.
64+
*
65+
* @see https://reactjs.org/blog/2019/02/06/react-v16.8.0.html#testing-hooks
66+
*/
67+
// the "void | undefined" is here to forbid any sneaky return values
68+
// tslint:disable-next-line: void-return
69+
export function act(callback: () => Promise<void | undefined>): Promise<undefined>;
5670
/**
5771
* Wrap any code rendering and triggering updates to your components into `act()` calls.
5872
*
@@ -71,6 +85,9 @@ export function act(callback: () => void | undefined): DebugPromiseLike;
7185
// Intentionally doesn't extend PromiseLike<never>.
7286
// Ideally this should be as hard to accidentally use as possible.
7387
export interface DebugPromiseLike {
74-
// the actual then() in here is 0-ary, but that doesn't count as a PromiseLike.
75-
then(onfulfilled: (value: never) => never, onrejected: (reason: never) => never): never;
88+
// the actual then() in here is 1-ary, but that doesn't count as a PromiseLike.
89+
then(
90+
onfulfilled: (value: never) => never,
91+
onrejected: (reason: never) => never,
92+
): never;
7693
}

types/react-test-renderer/react-test-renderer-tests.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,19 @@ shallowRenderer.getMountedInstance();
7070
// Only synchronous, void callbacks are acceptable for act()
7171
act(() => {});
7272
// $ExpectError
73-
act(async () => {});
74-
// $ExpectError
7573
act(() => null);
7674
// $ExpectError
7775
Promise.resolve(act(() => {}));
76+
77+
// async act is now acceptable in React 16.9,
78+
// but the result must be void or undefined
79+
Promise.resolve(act(async () => {}));
80+
81+
void (async () => {
82+
act(() => {});
83+
84+
await act(async () => {});
85+
await act(async () => undefined);
86+
// $ExpectError
87+
await act(async () => null);
88+
})();

types/react/index.d.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Type definitions for React 16.8
1+
// Type definitions for React 16.9
22
// Project: http://facebook.github.io/react/
33
// Definitions by: Asana <https://asana.com>
44
// AssureSign <http://www.assuresign.com>
@@ -349,13 +349,6 @@ declare namespace React {
349349

350350
/** A fallback react tree to show when a Suspense child (like React.lazy) suspends */
351351
fallback: NonNullable<ReactNode>|null;
352-
353-
// I tried looking at the code but I have no idea what it does.
354-
// https://github.com/facebook/react/issues/13206#issuecomment-432489986
355-
/**
356-
* Not implemented yet, requires unstable_ConcurrentMode
357-
*/
358-
// maxDuration?: number;
359352
}
360353
/**
361354
* This feature is not yet available for server-side rendering.
@@ -382,7 +375,7 @@ declare namespace React {
382375
onRender: ProfilerOnRenderCallback;
383376
}
384377

385-
const unstable_Profiler: ExoticComponent<ProfilerProps>;
378+
const Profiler: ExoticComponent<ProfilerProps>;
386379

387380
//
388381
// Component API
@@ -2199,6 +2192,7 @@ declare namespace React {
21992192
playsInline?: boolean;
22002193
poster?: string;
22012194
width?: number | string;
2195+
disablePictureInPicture?: boolean;
22022196
}
22032197

22042198
// this list is "complete" in that it contains every SVG attribute

types/react/test/tsx.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ const ForwardRef3 = React.forwardRef(
321321
<ForwardRef3 ref={divFnRef}/>;
322322
<ForwardRef3 ref={divRef}/>;
323323

324-
const Profiler = React.unstable_Profiler;
324+
const { Profiler } = React;
325325

326326
// 'id' is missing
327327
<Profiler />; // $ExpectError
@@ -357,8 +357,14 @@ const Profiler = React.unstable_Profiler;
357357
</Profiler>;
358358

359359
type ImgProps = React.ComponentProps<'img'>;
360-
// $ExpectType "async" | "auto" | "sync" | undefined
361-
type ImgPropsDecoding = ImgProps['decoding'];
360+
const imgProps: ImgProps = {};
361+
// the order of the strings in the union seems to vary
362+
// with the typescript version, so test assignment instead
363+
imgProps.decoding = 'async';
364+
imgProps.decoding = 'auto';
365+
imgProps.decoding = 'sync';
366+
// $ExpectError
367+
imgProps.decoding = 'nonsense';
362368
type ImgPropsWithRef = React.ComponentPropsWithRef<'img'>;
363369
// $ExpectType ((instance: HTMLImageElement | null) => void) | RefObject<HTMLImageElement> | null | undefined
364370
type ImgPropsWithRefRef = ImgPropsWithRef['ref'];

0 commit comments

Comments
 (0)