Skip to content

Commit e267345

Browse files
committed
[react] Add failing tests for returning ReactNode from an async Component
1 parent eff7ed8 commit e267345

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

types/react/test/tsx.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,15 @@ function elementTypeTests() {
772772
}
773773
}
774774

775+
const ReturnPromiseReactNode = async ({ children }: { children?: React.ReactNode }) => children;
776+
const FCPromiseReactNode: React.FC = ReturnReactNode;
777+
class RenderPromiseReactNode extends React.Component<{ children?: React.ReactNode }> {
778+
// @ts-expect-error class components cannot render async
779+
async render() {
780+
return this.props.children;
781+
}
782+
}
783+
775784
const ReturnWithLegacyContext = (props: { foo: string }, context: { bar: number }) => {
776785
return (
777786
<div>
@@ -865,6 +874,13 @@ function elementTypeTests() {
865874
// Will not type-check in a real project but accepted in DT tests since experimental.d.ts is part of compilation.
866875
React.createElement(RenderPromise);
867876

877+
// @ts-expect-error See https://github.com/microsoft/TypeScript/issues/59111
878+
<ReturnPromiseReactNode />;
879+
// @ts-expect-error See https://github.com/microsoft/TypeScript/issues/59111
880+
React.createElement(ReturnPromiseReactNode);
881+
<FCPromiseReactNode />;
882+
React.createElement(FCPromiseReactNode);
883+
868884
<ReturnWithLegacyContext foo="one" />;
869885
React.createElement(ReturnWithLegacyContext, { foo: "one" });
870886

types/react/ts5.0/test/tsx.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,16 @@ function elementTypeTests() {
761761
}
762762
}
763763

764+
const ReturnPromiseReactNode = async ({ children }: { children?: React.ReactNode }) => children;
765+
// @ts-expect-error experimental release channel only
766+
const FCPromiseReactNode: React.FC = ReturnReactNode;
767+
class RenderPromiseReactNode extends React.Component<{ children?: React.ReactNode }> {
768+
// @ts-expect-error class components cannot render async
769+
async render() {
770+
return this.props.children;
771+
}
772+
}
773+
764774
const ReturnWithLegacyContext = (props: { foo: string }, context: { bar: number }) => {
765775
return (
766776
<div>
@@ -865,6 +875,13 @@ function elementTypeTests() {
865875
// Will not type-check in a real project but accepted in DT tests since experimental.d.ts is part of compilation.
866876
React.createElement(RenderPromise);
867877

878+
// @ts-expect-error See https://github.com/microsoft/TypeScript/issues/59111
879+
<ReturnPromiseReactNode />;
880+
// @ts-expect-error See https://github.com/microsoft/TypeScript/issues/59111
881+
React.createElement(ReturnPromiseReactNode);
882+
<FCPromiseReactNode />;
883+
React.createElement(FCPromiseReactNode);
884+
868885
<ReturnWithLegacyContext foo="one" />;
869886
React.createElement(ReturnWithLegacyContext, { foo: "one" });
870887

0 commit comments

Comments
 (0)