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

Remove Guaranteed from CellSuccessData #9010

Closed
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
12 changes: 1 addition & 11 deletions packages/web/src/components/createCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,17 @@ export type CellFailureProps<TVariables extends OperationVariables = any> = {
updating?: boolean
}

// aka guarantee that all properties in T exist
// This is necessary for Cells, because if it doesn't exist it'll go to Empty or Failure
type Guaranteed<T> = {
[K in keyof T]-?: NonNullable<T[K]>
}

/**
* Use this type, if you are forwarding on the data from your Cell's Success component
* Because Cells automatically checks for "empty", or "errors" - if you receive the data type in your
* Success component, it means the data is guaranteed (and non-optional)
Comment on lines -75 to -83
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These comments are no longer accurate because we render Success if any property is present/non-empty. Other properties can still be missing/empty.

A custom isEmpty implementation or a missing Empty definition can also result in Success.

*
* @params TData = Type of data based on your graphql query. This can be imported from 'types/graphql'
* @example
* import type {FindPosts} from 'types/graphql'
*
* const { post } = CellSuccessData<FindPosts>
*
* post.id // post is non optional, so no need to do post?.id
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would only be true when all of the following are true:

  • Empty is defined
  • isEmpty is not customized, or its custom implementation retains the presence check (which is admittedly likely 🙂)
  • post is the only field in your graphql query, or all fields are present/non-empty

*
*/
export type CellSuccessData<TData = any> = Omit<Guaranteed<TData>, '__typename'>
export type CellSuccessData<TData = any> = Omit<TData, '__typename'>

/**
* @MARK not sure about this partial, but we need to do this for tests and storybook.
Expand Down