From bb1da8349e785c54fb4030f269602c900adf23a0 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Thu, 2 Nov 2023 16:31:33 +0100 Subject: [PATCH] work around TS 4.8-specific `infer X extends Y` (#11337) --- .api-reports/api-report-cache.md | 2 +- .api-reports/api-report-core.md | 2 +- .api-reports/api-report-react.md | 2 +- .api-reports/api-report-react_components.md | 2 +- .api-reports/api-report-react_context.md | 2 +- .api-reports/api-report-react_hoc.md | 2 +- .api-reports/api-report-react_hooks.md | 2 +- .api-reports/api-report-react_ssr.md | 2 +- .api-reports/api-report-testing.md | 2 +- .api-reports/api-report-testing_core.md | 2 +- .api-reports/api-report-utilities.md | 2 +- .api-reports/api-report.md | 2 +- .changeset/stupid-chairs-wait.md | 6 ++++++ src/cache/core/types/common.ts | 8 ++++++-- 14 files changed, 24 insertions(+), 14 deletions(-) create mode 100644 .changeset/stupid-chairs-wait.md diff --git a/.api-reports/api-report-cache.md b/.api-reports/api-report-cache.md index 34278f0c522..e10f450c8b7 100644 --- a/.api-reports/api-report-cache.md +++ b/.api-reports/api-report-cache.md @@ -885,7 +885,7 @@ export interface StoreObject { // Warning: (ae-forgotten-export) The symbol "AsStoreObject" needs to be exported by the entry point index.d.ts // // @public (undocumented) -type StoreObjectValueMaybeReference = StoreVal extends Array> ? ReadonlyArray | Reference> : StoreVal extends Record ? AsStoreObject | Reference : StoreVal; +type StoreObjectValueMaybeReference = StoreVal extends Array> ? StoreVal extends Array ? Item extends Record ? ReadonlyArray | Reference> : never : never : StoreVal extends Record ? AsStoreObject | Reference : StoreVal; // @public (undocumented) export type StoreValue = number | string | string[] | Reference | Reference[] | null | undefined | void | Object; diff --git a/.api-reports/api-report-core.md b/.api-reports/api-report-core.md index bd0acbce3df..c5d9202d915 100644 --- a/.api-reports/api-report-core.md +++ b/.api-reports/api-report-core.md @@ -2015,7 +2015,7 @@ export interface StoreObject { // Warning: (ae-forgotten-export) The symbol "AsStoreObject" needs to be exported by the entry point index.d.ts // // @public (undocumented) -type StoreObjectValueMaybeReference = StoreVal extends Array> ? ReadonlyArray | Reference> : StoreVal extends Record ? AsStoreObject | Reference : StoreVal; +type StoreObjectValueMaybeReference = StoreVal extends Array> ? StoreVal extends Array ? Item extends Record ? ReadonlyArray | Reference> : never : never : StoreVal extends Record ? AsStoreObject | Reference : StoreVal; // @public (undocumented) export type StoreValue = number | string | string[] | Reference | Reference[] | null | undefined | void | Object; diff --git a/.api-reports/api-report-react.md b/.api-reports/api-report-react.md index 267adc1a330..3d605b0c75d 100644 --- a/.api-reports/api-report-react.md +++ b/.api-reports/api-report-react.md @@ -1859,7 +1859,7 @@ interface StoreObject { // Warning: (ae-forgotten-export) The symbol "AsStoreObject" needs to be exported by the entry point index.d.ts // // @public (undocumented) -type StoreObjectValueMaybeReference = StoreVal extends Array> ? ReadonlyArray | Reference> : StoreVal extends Record ? AsStoreObject | Reference : StoreVal; +type StoreObjectValueMaybeReference = StoreVal extends Array> ? StoreVal extends Array ? Item extends Record ? ReadonlyArray | Reference> : never : never : StoreVal extends Record ? AsStoreObject | Reference : StoreVal; // @public (undocumented) type StoreValue = number | string | string[] | Reference | Reference[] | null | undefined | void | Object; diff --git a/.api-reports/api-report-react_components.md b/.api-reports/api-report-react_components.md index 1c8651938b5..fe5cd1acd2e 100644 --- a/.api-reports/api-report-react_components.md +++ b/.api-reports/api-report-react_components.md @@ -1594,7 +1594,7 @@ interface StoreObject { // Warning: (ae-forgotten-export) The symbol "AsStoreObject" needs to be exported by the entry point index.d.ts // // @public (undocumented) -type StoreObjectValueMaybeReference = StoreVal extends Array> ? ReadonlyArray | Reference> : StoreVal extends Record ? AsStoreObject | Reference : StoreVal; +type StoreObjectValueMaybeReference = StoreVal extends Array> ? StoreVal extends Array ? Item extends Record ? ReadonlyArray | Reference> : never : never : StoreVal extends Record ? AsStoreObject | Reference : StoreVal; // @public (undocumented) type StoreValue = number | string | string[] | Reference | Reference[] | null | undefined | void | Object; diff --git a/.api-reports/api-report-react_context.md b/.api-reports/api-report-react_context.md index 594fb04aeed..a7d24173bf6 100644 --- a/.api-reports/api-report-react_context.md +++ b/.api-reports/api-report-react_context.md @@ -1529,7 +1529,7 @@ interface StoreObject { // Warning: (ae-forgotten-export) The symbol "AsStoreObject" needs to be exported by the entry point index.d.ts // // @public (undocumented) -type StoreObjectValueMaybeReference = StoreVal extends Array> ? ReadonlyArray | Reference> : StoreVal extends Record ? AsStoreObject | Reference : StoreVal; +type StoreObjectValueMaybeReference = StoreVal extends Array> ? StoreVal extends Array ? Item extends Record ? ReadonlyArray | Reference> : never : never : StoreVal extends Record ? AsStoreObject | Reference : StoreVal; // @public (undocumented) type StoreValue = number | string | string[] | Reference | Reference[] | null | undefined | void | Object; diff --git a/.api-reports/api-report-react_hoc.md b/.api-reports/api-report-react_hoc.md index 017659e7ecc..e3a06451eb7 100644 --- a/.api-reports/api-report-react_hoc.md +++ b/.api-reports/api-report-react_hoc.md @@ -1550,7 +1550,7 @@ interface StoreObject { // Warning: (ae-forgotten-export) The symbol "AsStoreObject" needs to be exported by the entry point index.d.ts // // @public (undocumented) -type StoreObjectValueMaybeReference = StoreVal extends Array> ? ReadonlyArray | Reference> : StoreVal extends Record ? AsStoreObject | Reference : StoreVal; +type StoreObjectValueMaybeReference = StoreVal extends Array> ? StoreVal extends Array ? Item extends Record ? ReadonlyArray | Reference> : never : never : StoreVal extends Record ? AsStoreObject | Reference : StoreVal; // @public (undocumented) type StoreValue = number | string | string[] | Reference | Reference[] | null | undefined | void | Object; diff --git a/.api-reports/api-report-react_hooks.md b/.api-reports/api-report-react_hooks.md index 110739c8df9..a26e8bd68a5 100644 --- a/.api-reports/api-report-react_hooks.md +++ b/.api-reports/api-report-react_hooks.md @@ -1752,7 +1752,7 @@ interface StoreObject { // Warning: (ae-forgotten-export) The symbol "AsStoreObject" needs to be exported by the entry point index.d.ts // // @public (undocumented) -type StoreObjectValueMaybeReference = StoreVal extends Array> ? ReadonlyArray | Reference> : StoreVal extends Record ? AsStoreObject | Reference : StoreVal; +type StoreObjectValueMaybeReference = StoreVal extends Array> ? StoreVal extends Array ? Item extends Record ? ReadonlyArray | Reference> : never : never : StoreVal extends Record ? AsStoreObject | Reference : StoreVal; // @public (undocumented) type StoreValue = number | string | string[] | Reference | Reference[] | null | undefined | void | Object; diff --git a/.api-reports/api-report-react_ssr.md b/.api-reports/api-report-react_ssr.md index 5b11d65622a..5e51549fce7 100644 --- a/.api-reports/api-report-react_ssr.md +++ b/.api-reports/api-report-react_ssr.md @@ -1516,7 +1516,7 @@ interface StoreObject { // Warning: (ae-forgotten-export) The symbol "AsStoreObject" needs to be exported by the entry point index.d.ts // // @public (undocumented) -type StoreObjectValueMaybeReference = StoreVal extends Array> ? ReadonlyArray | Reference> : StoreVal extends Record ? AsStoreObject | Reference : StoreVal; +type StoreObjectValueMaybeReference = StoreVal extends Array> ? StoreVal extends Array ? Item extends Record ? ReadonlyArray | Reference> : never : never : StoreVal extends Record ? AsStoreObject | Reference : StoreVal; // @public (undocumented) type StoreValue = number | string | string[] | Reference | Reference[] | null | undefined | void | Object; diff --git a/.api-reports/api-report-testing.md b/.api-reports/api-report-testing.md index bdbed73258e..9d175464835 100644 --- a/.api-reports/api-report-testing.md +++ b/.api-reports/api-report-testing.md @@ -1548,7 +1548,7 @@ interface StoreObject { // Warning: (ae-forgotten-export) The symbol "AsStoreObject" needs to be exported by the entry point index.d.ts // // @public (undocumented) -type StoreObjectValueMaybeReference = StoreVal extends Array> ? ReadonlyArray | Reference> : StoreVal extends Record ? AsStoreObject | Reference : StoreVal; +type StoreObjectValueMaybeReference = StoreVal extends Array> ? StoreVal extends Array ? Item extends Record ? ReadonlyArray | Reference> : never : never : StoreVal extends Record ? AsStoreObject | Reference : StoreVal; // @public (undocumented) type StoreValue = number | string | string[] | Reference | Reference[] | null | undefined | void | Object; diff --git a/.api-reports/api-report-testing_core.md b/.api-reports/api-report-testing_core.md index f5de976f0c6..a95a55f8e2a 100644 --- a/.api-reports/api-report-testing_core.md +++ b/.api-reports/api-report-testing_core.md @@ -1504,7 +1504,7 @@ interface StoreObject { // Warning: (ae-forgotten-export) The symbol "AsStoreObject" needs to be exported by the entry point index.d.ts // // @public (undocumented) -type StoreObjectValueMaybeReference = StoreVal extends Array> ? ReadonlyArray | Reference> : StoreVal extends Record ? AsStoreObject | Reference : StoreVal; +type StoreObjectValueMaybeReference = StoreVal extends Array> ? StoreVal extends Array ? Item extends Record ? ReadonlyArray | Reference> : never : never : StoreVal extends Record ? AsStoreObject | Reference : StoreVal; // @public (undocumented) type StoreValue = number | string | string[] | Reference | Reference[] | null | undefined | void | Object; diff --git a/.api-reports/api-report-utilities.md b/.api-reports/api-report-utilities.md index 742cf060348..90e3cbaae41 100644 --- a/.api-reports/api-report-utilities.md +++ b/.api-reports/api-report-utilities.md @@ -2298,7 +2298,7 @@ export interface StoreObject { } // @public (undocumented) -type StoreObjectValueMaybeReference = StoreVal extends Array> ? ReadonlyArray | Reference> : StoreVal extends Record ? AsStoreObject | Reference : StoreVal; +type StoreObjectValueMaybeReference = StoreVal extends Array> ? StoreVal extends Array ? Item extends Record ? ReadonlyArray | Reference> : never : never : StoreVal extends Record ? AsStoreObject | Reference : StoreVal; // @public (undocumented) export type StoreValue = number | string | string[] | Reference | Reference[] | null | undefined | void | Object; diff --git a/.api-reports/api-report.md b/.api-reports/api-report.md index 3004669da51..c73cfb60ec7 100644 --- a/.api-reports/api-report.md +++ b/.api-reports/api-report.md @@ -2462,7 +2462,7 @@ export interface StoreObject { // Warning: (ae-forgotten-export) The symbol "AsStoreObject" needs to be exported by the entry point index.d.ts // // @public (undocumented) -type StoreObjectValueMaybeReference = StoreVal extends Array> ? ReadonlyArray | Reference> : StoreVal extends Record ? AsStoreObject | Reference : StoreVal; +type StoreObjectValueMaybeReference = StoreVal extends Array> ? StoreVal extends Array ? Item extends Record ? ReadonlyArray | Reference> : never : never : StoreVal extends Record ? AsStoreObject | Reference : StoreVal; // @public (undocumented) export type StoreValue = number | string | string[] | Reference | Reference[] | null | undefined | void | Object; diff --git a/.changeset/stupid-chairs-wait.md b/.changeset/stupid-chairs-wait.md new file mode 100644 index 00000000000..fb7c32fd1be --- /dev/null +++ b/.changeset/stupid-chairs-wait.md @@ -0,0 +1,6 @@ +--- +"@apollo/client": patch +--- + +#11206 used the TypeScript syntax `infer X extends Y` that was introduced in TS 4.8. +This caused some problems for some users, so we are rolling back to a more backwars-compatible (albeit slightly less performant) type. diff --git a/src/cache/core/types/common.ts b/src/cache/core/types/common.ts index 19200d4845e..9dc18d9197f 100644 --- a/src/cache/core/types/common.ts +++ b/src/cache/core/types/common.ts @@ -106,9 +106,13 @@ export type Modifier = ( ) => T | DeleteModifier | InvalidateModifier; type StoreObjectValueMaybeReference = StoreVal extends Array< - infer Item extends Record + Record > - ? ReadonlyArray | Reference> + ? StoreVal extends Array + ? Item extends Record + ? ReadonlyArray | Reference> + : never + : never : StoreVal extends Record ? AsStoreObject | Reference : StoreVal;