@apollo/client@4.2.0-alpha.2
Breaking Changes📦 apollo-clientView on GitHub →
⚠ 2 breaking✨ 3 features🐛 1 fixes⚡ 1 deprecations🔧 7 symbols
Summary
Apollo Client 4.2 introduces 'classic' and 'modern' signature styles, enhancing type safety by synchronizing hook/method return types with declared default options. This requires explicit type declaration for used default options to maintain type accuracy.
⚠️ Breaking Changes
- Using `defaultOptions` in the `ApolloClient` constructor without globally declaring the types for those options in `ApolloClient.DeclareDefaultOptions` will now result in a TypeScript error, whereas it was previously valid.
- When using 'modern' signatures (activated by declaring a non-optional property in `DeclareDefaultOptions` or setting `signatureStyle: "modern"`), manually specifying TypeScript generics (e.g., `useSuspenseQuery<MyData>(...)`) will produce a TypeScript error.
Migration Steps
- If you use `defaultOptions` in your `ApolloClient` constructor, you must now declare the types for those options globally in `apollo.d.ts` using `ApolloClient.DeclareDefaultOptions` to avoid TypeScript errors.
- If you rely on manually specified TypeScript generics for hooks/methods and wish to keep using 'classic' signatures, ensure you do not declare any non-optional properties in `DeclareDefaultOptions` or explicitly set `TypeOverrides { signatureStyle: "classic" }` in `apollo.d.ts`.
✨ New Features
- Introduction of 'classic' and 'modern' method and hook signatures. 'Classic' preserves pre-4.2 behavior, while 'modern' signatures automatically incorporate declared `defaultOptions` into return types for more accurate typing.
- Ability to globally declare types for values used in `defaultOptions` via `ApolloClient.DeclareDefaultOptions` to ensure accurate type inference for hooks and methods when defaults are set.
- Ability to manually switch to 'modern' signatures globally via `TypeOverrides { signatureStyle: "modern" }` without declaring `defaultOptions`.
🐛 Bug Fixes
- Synchronized method and hook return types with `defaultOptions`. Previously, if `errorPolicy: 'all'` was set as a default, hooks would incorrectly return data as `TData` instead of `TData | undefined`.
Affected Symbols
⚡ Deprecations
- Manually specifying TypeScript generics for methods and hooks (e.g., `useSuspenseQuery<MyData>(...)`) is discouraged; use `TypedDocumentNode` instead for automatic type inference.