Skip to content

Commit

Permalink
fix(types): type structural sharing as unknown (#6888)
Browse files Browse the repository at this point in the history
  • Loading branch information
TkDodo committed Feb 13, 2024
1 parent 7a98470 commit aad4078
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/framework/react/reference/useQuery.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const {
- If set, this value will be used as the placeholder data for this particular query observer while the query is still in the `pending` state.
- `placeholderData` is **not persisted** to the cache
- If you provide a function for `placeholderData`, as a first argument you will receive previously watched query data if available, and the second argument will be the complete previousQuery instance.
- `structuralSharing: boolean | (<T>(oldData: T | undefined, newData: T) => T)`
- `structuralSharing: boolean | (oldData: unknown | undefined, newData: unknown) => unknown)`
- Optional
- Defaults to `true`
- If set to `false`, structural sharing between query results will be disabled.
Expand Down
4 changes: 3 additions & 1 deletion packages/query-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ export interface QueryOptions<
* Set this to a function which accepts the old and new data and returns resolved data of the same type to implement custom structural sharing logic.
* Defaults to `true`.
*/
structuralSharing?: boolean | (<T>(oldData: T | undefined, newData: T) => T)
structuralSharing?:
| boolean
| ((oldData: unknown | undefined, newData: unknown) => unknown)
_defaulted?: boolean
/**
* Additional payload to be stored on each query.
Expand Down
2 changes: 1 addition & 1 deletion packages/query-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ export function replaceData<
TOptions extends QueryOptions<any, any, any, any>,
>(prevData: TData | undefined, data: TData, options: TOptions): TData {
if (typeof options.structuralSharing === 'function') {
return options.structuralSharing(prevData, data)
return options.structuralSharing(prevData, data) as TData
} else if (options.structuralSharing !== false) {
// Structurally share data between prev and new data if needed
return replaceEqualDeep(prevData, data)
Expand Down

0 comments on commit aad4078

Please sign in to comment.