Skip to content

Commit

Permalink
fix(react): change return type of Consumers as JSX.Element (#891)
Browse files Browse the repository at this point in the history
# Overview

<!--
    A clear and concise description of what this pr is about.
 -->

Same reason with #887

## PR Checklist

- [x] I did below actions if need

1. I read the [Contributing
Guide](https://github.com/suspensive/react/blob/main/CONTRIBUTING.md)
2. I added documents and tests.
  • Loading branch information
manudeli authored May 25, 2024
1 parent 42136e4 commit be1b7ee
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/wicked-mails-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@suspensive/react": patch
---

fix(react): change return type of Consumers as JSX.Element
6 changes: 6 additions & 0 deletions packages/react-query/src/SuspenseInfiniteQuery.test-d.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { queryFn, queryKey } from '@suspensive/test-utils'
import type { InfiniteData } from '@tanstack/react-query'
import type { ReactNode } from 'react'
import { describe, expectTypeOf, it } from 'vitest'
import { SuspenseInfiniteQuery } from './SuspenseInfiniteQuery'
import type { UseSuspenseInfiniteQueryResult } from './useSuspenseInfiniteQuery'
Expand Down Expand Up @@ -92,5 +93,10 @@ describe('<SuspenseInfiniteQuery/>', () => {
{() => <></>}
</SuspenseInfiniteQuery>
).toEqualTypeOf<JSX.Element>()
expectTypeOf(
<SuspenseInfiniteQuery queryKey={queryKey} queryFn={queryFn}>
{() => <></>}
</SuspenseInfiniteQuery>
).not.toEqualTypeOf<ReactNode>()
})
})
6 changes: 6 additions & 0 deletions packages/react-query/src/SuspenseQuery.test-d.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { queryFn, queryKey } from '@suspensive/test-utils'
import type { ReactNode } from 'react'
import { describe, expectTypeOf, it } from 'vitest'
import { SuspenseQuery } from './SuspenseQuery'
import type { UseSuspenseQueryResult } from './useSuspenseQuery'
Expand Down Expand Up @@ -84,5 +85,10 @@ describe('<SuspenseQuery/>', () => {
{() => <></>}
</SuspenseQuery>
).toEqualTypeOf<JSX.Element>()
expectTypeOf(
<SuspenseQuery queryKey={queryKey} queryFn={queryFn}>
{() => <></>}
</SuspenseQuery>
).not.toEqualTypeOf<ReactNode>()
})
})
7 changes: 6 additions & 1 deletion packages/react/src/ErrorBoundary.test-d.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CustomError, CustomNotError } from '@suspensive/test-utils'
import type { ComponentProps } from 'react'
import type { ComponentProps, ReactNode } from 'react'
import { ErrorBoundary } from './ErrorBoundary'
import type { ConstructorType } from './utility-types'

Expand Down Expand Up @@ -34,4 +34,9 @@ describe('<ErrorBoundary/>', () => {
></ErrorBoundary>
)
})

it('type check', () => {
expectTypeOf(<ErrorBoundary.Consumer>{() => <></>}</ErrorBoundary.Consumer>).toEqualTypeOf<JSX.Element>()
expectTypeOf(<ErrorBoundary.Consumer>{() => <></>}</ErrorBoundary.Consumer>).not.toEqualTypeOf<ReactNode>()
})
})
5 changes: 3 additions & 2 deletions packages/react/src/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ export const ErrorBoundary = Object.assign(
return ErrorBoundary
})(),
{
Consumer: ({ children }: { children: (errorBoundary: ReturnType<typeof useErrorBoundary>) => ReactNode }) =>
children(useErrorBoundary()),
Consumer: ({ children }: { children: (errorBoundary: ReturnType<typeof useErrorBoundary>) => ReactNode }) => (
<>{children(useErrorBoundary())}</>
),
}
)

Expand Down
11 changes: 11 additions & 0 deletions packages/react/src/ErrorBoundaryGroup.test-d.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { ReactNode } from 'react'
import { ErrorBoundaryGroup } from './ErrorBoundaryGroup'

describe('ErrorBoundaryGroup', () => {
it('type check', () => {
expectTypeOf(<ErrorBoundaryGroup.Consumer>{() => <></>}</ErrorBoundaryGroup.Consumer>).toEqualTypeOf<JSX.Element>()
expectTypeOf(
<ErrorBoundaryGroup.Consumer>{() => <></>}</ErrorBoundaryGroup.Consumer>
).not.toEqualTypeOf<ReactNode>()
})
})
2 changes: 1 addition & 1 deletion packages/react/src/ErrorBoundaryGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const ErrorBoundaryGroup = Object.assign(
children,
}: {
children: (errorBoundaryGroup: ReturnType<typeof useErrorBoundaryGroup>) => ReactNode
}) => children(useErrorBoundaryGroup()),
}) => <>{children(useErrorBoundaryGroup())}</>,
}
)

Expand Down

0 comments on commit be1b7ee

Please sign in to comment.