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

Fix link/core/types to be compatible with graphql typings while TypeScript exactOptionalPropertyTypes mode is enabled #10497

Merged
merged 11 commits into from
Feb 10, 2023
5 changes: 5 additions & 0 deletions .changeset/tricky-berries-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/client": patch
---

Update `SingleExecutionResult` and `IncrementalPayload`'s `data` types such that they no longer include `undefined`, which was not a valid runtime value, to fix errors when TypeScript's `exactOptionalPropertyTypes` is enabled.
8 changes: 3 additions & 5 deletions src/link/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ export { DocumentNode };
import { Observable } from "../../utilities";

export type Path = ReadonlyArray<string | number>;
type Data<T> = T | null | undefined;


interface ExecutionPatchResultBase {
hasNext?: boolean;
Expand All @@ -17,7 +15,7 @@ export interface ExecutionPatchInitialResult<
TExtensions = Record<string, any>
> extends ExecutionPatchResultBase {
// if data is present, incremental is not
data: Data<TData>;
data: TData | null | undefined;
incremental?: never;
errors?: ReadonlyArray<GraphQLError>;
extensions?: TExtensions;
Expand All @@ -29,7 +27,7 @@ export interface IncrementalPayload<
> {
// data and path must both be present
// https://github.com/graphql/graphql-spec/pull/742/files#diff-98d0cd153b72b63c417ad4238e8cc0d3385691ccbde7f7674bc0d2a718b896ecR288-R293
data: Data<TData>;
data: TData | null;
label?: string;
path: Path;
errors?: ReadonlyArray<GraphQLError>;
Expand Down Expand Up @@ -79,7 +77,7 @@ export interface SingleExecutionResult<
TContext = DefaultContext,
TExtensions = Record<string, any>
> extends ExecutionResult<TData, TExtensions> {
data?: Data<TData>;
data?: TData | null;
context?: TContext;
}

Expand Down