Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(web) type NonSuspenseCellQueryResult... #11639

Merged
merged 3 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changesets/11639.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- fix(web) type NonSuspenseCallQueryResult... (#11639) by @richard-stafflink

The result you get back as `queryResult` is now properly typed. Typically the
type will be something like `FindPostById`, i.e. the first type that is passed
to `CellSuccessProps` (instead of just being `any`).
15 changes: 11 additions & 4 deletions packages/web/src/components/cell/cellTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ export type CellProps<
>

export type CellLoadingProps<TVariables extends OperationVariables = any> = {
queryResult?: NonSuspenseCellQueryResult<TVariables> | SuspenseCellQueryResult
queryResult?:
| NonSuspenseCellQueryResult<TVariables, any>
| SuspenseCellQueryResult
}

export type CellFailureProps<TVariables extends OperationVariables = any> = {
queryResult?: NonSuspenseCellQueryResult<TVariables> | SuspenseCellQueryResult
queryResult?:
| NonSuspenseCellQueryResult<TVariables, any>
| SuspenseCellQueryResult
error?: QueryOperationResult['error'] | Error // for tests and storybook

/**
Expand Down Expand Up @@ -106,7 +110,9 @@ export type CellSuccessProps<
TData = any,
TVariables extends OperationVariables = any,
> = {
queryResult?: NonSuspenseCellQueryResult<TVariables> | SuspenseCellQueryResult
queryResult?:
| NonSuspenseCellQueryResult<TVariables, TData>
| SuspenseCellQueryResult
updating?: boolean
} & A.Compute<CellSuccessData<TData>> // pre-computing makes the types more readable on hover

Expand Down Expand Up @@ -199,8 +205,9 @@ export type SuspendingSuccessProps = React.PropsWithChildren<

export type NonSuspenseCellQueryResult<
TVariables extends OperationVariables = any,
TData = any,
> = Partial<
Omit<QueryOperationResult<any, TVariables>, 'loading' | 'error' | 'data'>
Omit<QueryOperationResult<TData, TVariables>, 'loading' | 'error' | 'data'>
>

// We call this queryResult in createCell, sadly a very overloaded term
Expand Down
Loading