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

Address feedback on pagination examples raised in #5881. #5884

Merged
merged 2 commits into from
Jan 30, 2020

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented Jan 30, 2020

Thanks to @tafelito for actually trying out the code examples in the new cache policies documentation (see #5881)! I have simplified the suggested edits to the examples, but (I hope) preserved their intent.

As for the TypeScript changes, we were previously defaulting TExisting to StoreValue, and TIncoming to TExisting, but that was never really helpful (and sometimes just frustrating), because the definition of the StoreValue type reads like an incomplete list of some of the types you might find inside the cache:

export type StoreValue =
  | number
  | string
  | string[]
  | Reference
  | Reference[]
  | null
  | undefined
  | void
  | Object;

When you're writing a specific read or merge function, you almost always have a much better idea what type of data you're dealing with, so there's pretty much zero value in thinking through these cases, when you can just name your own parameter types and be done with it.

This is one of those rare cases when defaulting to any is a good option, because it places the responsibility on the developer to handle all possible cases, using their application-level knowledge.

Should help with the type issues reported in #5881, by defaulting
TExisting and TIncoming to any.

The last time I tried this, I ran into problems when the user-supplied
types were primitive (already read-only) types like string, since string
values are not assignable to Readonly<any> parameters. This time, I was
able to work around that dubious error using the SafeReadonly<T> type.
Follow-up to #5677.

Thanks to @tafelito for actually trying out the code examples in the new
cache policies documentation!
Copy link
Member

@hwillson hwillson left a comment

Choose a reason for hiding this comment

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

👍 @benjamn (and thanks @tafelito!).

@benjamn benjamn merged commit c5d5d27 into master Jan 30, 2020
@benjamn benjamn deleted the relax-read-and-merge-default-parameter-types branch January 30, 2020 22:08
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants