Skip to content

Commit

Permalink
Fix link/core/types to be compatible with graphql typings while TypeS…
Browse files Browse the repository at this point in the history
…cript strict mode is on

When importing `@apollo/client` in a project with TS 4.9, graphql 16.6 and `strict: true`, we see the following compilation error:

```
./node_modules/@apollo/client/link/core/types.d.ts(44,18): error TS2430: Interface 'SingleExecutionResult<TData, TContext, TExtensions>' incorrectly extends interface 'ExecutionResult<TData, TExtensions>'.
  Types of property 'data' are incompatible.
    Type 'Data<TData>' is not assignable to type 'TData | null'.
      Type 'undefined' is not assignable to type 'TData | null'.
```

Because `Data<TData>` expands to:
```ts
  data?: TData | undefined | null
```

Which is subtly different from:
```ts
  data?: TData | null
```

This fixes the type to be compatible.
  • Loading branch information
nevir committed Jan 30, 2023
1 parent b4a4bd1 commit 0ba637b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
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
---

Fix types to be free of errors when exactOptionalPropertyTypes is enabled.
2 changes: 1 addition & 1 deletion src/link/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export interface SingleExecutionResult<
TContext = DefaultContext,
TExtensions = Record<string, any>
> extends ExecutionResult<TData, TExtensions> {
data?: Data<TData>;
data?: TData | null;
context?: TContext;
}

Expand Down

0 comments on commit 0ba637b

Please sign in to comment.