Skip to content

Commit

Permalink
fix(react): change defineSuspense function signature (#1336)
Browse files Browse the repository at this point in the history
# Overview

I made modifications because, when `componentPropsClientOnly` is set to
`false`, it returns `Suspense`, but the overloaded function signature
indicated that it returns `SuspenseClientOnly`.

## PR Checklist

- [x] I did below actions if need

1. I read the [Contributing
Guide](https://github.com/toss/suspensive/blob/main/CONTRIBUTING.md)
2. I added documents and tests.

---------

Co-authored-by: Jonghyeon Ko <[email protected]>
  • Loading branch information
dayongkr and manudeli authored Oct 26, 2024
1 parent e9d4785 commit 91d8ae1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 32 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-laws-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@suspensive/react": patch
---

fix(react): change `defineSuspense` function signature
10 changes: 5 additions & 5 deletions packages/react/src/utils/defineSuspense.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ describe('defineSuspense', () => {
it('type check', () => {
expectTypeOf(defineSuspense({ componentPropsClientOnly: true })).toEqualTypeOf<typeof SuspenseClientOnly>()
expectTypeOf(defineSuspense({ defaultPropsClientOnly: true })).toEqualTypeOf<typeof SuspenseClientOnly>()
expectTypeOf(defineSuspense({ componentPropsClientOnly: true, defaultPropsClientOnly: undefined })).toEqualTypeOf<
expectTypeOf(defineSuspense({ defaultPropsClientOnly: undefined, componentPropsClientOnly: true })).toEqualTypeOf<
typeof SuspenseClientOnly
>()
expectTypeOf(defineSuspense({ componentPropsClientOnly: undefined, defaultPropsClientOnly: true })).toEqualTypeOf<
expectTypeOf(defineSuspense({ defaultPropsClientOnly: true, componentPropsClientOnly: undefined })).toEqualTypeOf<
typeof SuspenseClientOnly
>()
expectTypeOf(defineSuspense({ defaultPropsClientOnly: true, componentPropsClientOnly: true })).toEqualTypeOf<
typeof SuspenseClientOnly
>()
expectTypeOf(defineSuspense({ defaultPropsClientOnly: true, componentPropsClientOnly: false })).toEqualTypeOf<
typeof SuspenseClientOnly
>()
expectTypeOf(defineSuspense({ defaultPropsClientOnly: false, componentPropsClientOnly: true })).toEqualTypeOf<
typeof SuspenseClientOnly
>()
expectTypeOf(defineSuspense({ defaultPropsClientOnly: true, componentPropsClientOnly: false })).toEqualTypeOf<
typeof Suspense
>()
expectTypeOf(defineSuspense({ defaultPropsClientOnly: false, componentPropsClientOnly: false })).toEqualTypeOf<
typeof Suspense
>()
Expand Down
42 changes: 15 additions & 27 deletions packages/react/src/utils/defineSuspense.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,23 @@ export const SuspenseClientOnly = (props: SuspenseProps) => (
</ClientOnly>
)

/* eslint-disable @typescript-eslint/unified-signatures */
export function defineSuspense(options: { componentPropsClientOnly: true }): typeof SuspenseClientOnly
export function defineSuspense(options: { defaultPropsClientOnly: true }): typeof SuspenseClientOnly
export function defineSuspense(options: {
componentPropsClientOnly: true
defaultPropsClientOnly: undefined
}): typeof SuspenseClientOnly
export function defineSuspense(options: {
componentPropsClientOnly: undefined
defaultPropsClientOnly: true
}): typeof SuspenseClientOnly
export function defineSuspense(options: {
componentPropsClientOnly: true
defaultPropsClientOnly: true
}): typeof SuspenseClientOnly
export function defineSuspense(options: {
componentPropsClientOnly: true
defaultPropsClientOnly: false
}): typeof SuspenseClientOnly
export function defineSuspense(options: {
componentPropsClientOnly: false
defaultPropsClientOnly: true
}): typeof SuspenseClientOnly
export function defineSuspense(
options:
| {
componentPropsClientOnly: true
defaultPropsClientOnly?: boolean
}
| {
componentPropsClientOnly?: undefined
defaultPropsClientOnly: true
}
): typeof SuspenseClientOnly

export function defineSuspense(options: {
componentPropsClientOnly: false
defaultPropsClientOnly: false
componentPropsClientOnly?: boolean
defaultPropsClientOnly?: boolean
}): typeof Suspense
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export function defineSuspense(options: {}): typeof Suspense

export function defineSuspense({
defaultPropsClientOnly,
componentPropsClientOnly,
Expand Down

0 comments on commit 91d8ae1

Please sign in to comment.