Skip to content

Commit

Permalink
fix(web) type NonSuspenseCellQueryResult... (#11639)
Browse files Browse the repository at this point in the history
Co-authored-by: Tobbe Lundberg <tobbe@tlundberg.com>
  • Loading branch information
2 people authored and Josh-Walker-GM committed Oct 8, 2024
1 parent b4113c2 commit e9c2bcc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
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

0 comments on commit e9c2bcc

Please sign in to comment.