Skip to content

Commit 76d6d4d

Browse files
authored
Ensure we unwrap custom .then() (#4547)
1 parent aee8285 commit 76d6d4d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

compat/src/suspense.d.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { Component, ComponentChild, ComponentChildren } from '../../src';
33
//
44
// Suspense/lazy
55
// -----------------------------------
6-
export function lazy<T>(loader: () => Promise<{ default: T } | T>): T;
6+
export function lazy<T>(
7+
loader: () => Promise<{ default: T } | T>
8+
): T extends { default: infer U } ? U : T;
79

810
export interface SuspenseProps {
911
children?: ComponentChildren;

compat/test/ts/suspense.tsx

+15
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,18 @@ function ReactSuspenseListTester(_props: any) {
5050
</React.SuspenseList>
5151
);
5252
}
53+
54+
const Comp = () => <p>Hello world</p>;
55+
56+
const importComponent = async () => {
57+
return { MyComponent: Comp };
58+
};
59+
60+
const Lazy = React.lazy(() =>
61+
importComponent().then(mod => ({ default: mod.MyComponent }))
62+
);
63+
64+
// eslint-disable-next-line
65+
function App() {
66+
return <Lazy />;
67+
}

0 commit comments

Comments
 (0)