From 8a883d8a1c8899f94a3e2ae09cb2069bde2b2150 Mon Sep 17 00:00:00 2001 From: Ian MacLeod Date: Fri, 10 Feb 2023 08:14:49 -0800 Subject: [PATCH] Fix link/core/types when TypeScript exactOptionalPropertyTypes mode is enabled (#10497) --------- Co-authored-by: alessia --- .changeset/tricky-berries-perform.md | 5 +++++ src/link/core/types.ts | 8 +++----- 2 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 .changeset/tricky-berries-perform.md diff --git a/.changeset/tricky-berries-perform.md b/.changeset/tricky-berries-perform.md new file mode 100644 index 00000000000..b12df6fd26a --- /dev/null +++ b/.changeset/tricky-berries-perform.md @@ -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. diff --git a/src/link/core/types.ts b/src/link/core/types.ts index 230f51dea6b..0add4d9d666 100644 --- a/src/link/core/types.ts +++ b/src/link/core/types.ts @@ -5,8 +5,6 @@ export { DocumentNode }; import { Observable } from "../../utilities"; export type Path = ReadonlyArray; -type Data = T | null | undefined; - interface ExecutionPatchResultBase { hasNext?: boolean; @@ -17,7 +15,7 @@ export interface ExecutionPatchInitialResult< TExtensions = Record > extends ExecutionPatchResultBase { // if data is present, incremental is not - data: Data; + data: TData | null | undefined; incremental?: never; errors?: ReadonlyArray; extensions?: TExtensions; @@ -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; + data: TData | null; label?: string; path: Path; errors?: ReadonlyArray; @@ -79,7 +77,7 @@ export interface SingleExecutionResult< TContext = DefaultContext, TExtensions = Record > extends ExecutionResult { - data?: Data; + data?: TData | null; context?: TContext; }