Skip to content

Commit f6d0efa

Browse files
CarsonFjerelmiller
andauthored
Fix cache.modify() mapping readonly arrays to singular reference (#12983)
Co-authored-by: Jerel Miller <[email protected]>
1 parent c34538e commit f6d0efa

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

.api-reports/api-report-cache.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ type StorageType = Record<string, any>;
871871
export { StoreObject }
872872

873873
// @public (undocumented)
874-
type StoreObjectValueMaybeReference<StoreVal> = StoreVal extends Array<Record<string, any>> ? StoreVal extends Array<infer Item> ? [
874+
type StoreObjectValueMaybeReference<StoreVal> = StoreVal extends ReadonlyArray<Record<string, any>> ? StoreVal extends ReadonlyArray<infer Item> ? [
875875
Item
876876
] extends [Record<string, any>] ? ReadonlyArray<AsStoreObject<Item> | Reference> : never : never : StoreVal extends Record<string, any> ? AsStoreObject<StoreVal> | Reference : StoreVal;
877877

.api-reports/api-report.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2514,7 +2514,7 @@ export interface StoreObject {
25142514
// Warning: (ae-forgotten-export) The symbol "AsStoreObject" needs to be exported by the entry point index.d.ts
25152515
//
25162516
// @public (undocumented)
2517-
type StoreObjectValueMaybeReference<StoreVal> = StoreVal extends Array<Record<string, any>> ? StoreVal extends Array<infer Item> ? [
2517+
type StoreObjectValueMaybeReference<StoreVal> = StoreVal extends ReadonlyArray<Record<string, any>> ? StoreVal extends ReadonlyArray<infer Item> ? [
25182518
Item
25192519
] extends [Record<string, any>] ? ReadonlyArray<AsStoreObject<Item> | Reference> : never : never : StoreVal extends Record<string, any> ? AsStoreObject<StoreVal> | Reference : StoreVal;
25202520

.changeset/loud-cherries-attend.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@apollo/client": patch
3+
---
4+
5+
Fix cache.modify() mapping readonly arrays to singular reference

src/cache/core/__tests__/cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ describe.skip("Cache type tests", () => {
559559
test("Allows partial return data", () => {
560560
const cache = new TestCache();
561561
cache.modify<{
562-
union: Array<
562+
union: ReadonlyArray<
563563
| { __typename: "Type1"; a: string; c: { foo: string } }
564564
| { __typename: "Type2"; b: string; d: { bar: number } }
565565
>;

src/cache/core/types/common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ export type Modifier<T> = (
112112
) => DeepPartial<T> | DeleteModifier | InvalidateModifier | undefined;
113113

114114
type StoreObjectValueMaybeReference<StoreVal> =
115-
StoreVal extends Array<Record<string, any>> ?
116-
StoreVal extends Array<infer Item> ?
115+
StoreVal extends ReadonlyArray<Record<string, any>> ?
116+
StoreVal extends ReadonlyArray<infer Item> ?
117117
[Item] extends [Record<string, any>] ?
118118
ReadonlyArray<AsStoreObject<Item> | Reference>
119119
: never

0 commit comments

Comments
 (0)