Skip to content

Commit

Permalink
Fix refetchQueries in TypeScript 4.3 and above
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatown committed Nov 30, 2021
1 parent 8b2b4f3 commit 56aedff
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 44 deletions.
5 changes: 5 additions & 0 deletions .changeset/rotten-gorillas-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ts-gql/apollo": minor
---

Fixed support for TypeScript 4.3 and above in `refetchQueries` and dropped support for TypeScript 4.1 or below.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"react": "^16.14.0",
"react-dom": "^16.14.0",
"tsd": "^0.14.0",
"typescript": "^4.1.3"
"typescript": "^4.5.2"
},
"manypkg": {
"defaultBranch": "main"
Expand Down
18 changes: 7 additions & 11 deletions packages/apollo/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
BaseTypedMutation,
BaseOperations,
AllDocuments,
BaseDocumentTypes,
BaseTypedFragment,
FragmentData,
BaseDocumentTypes,
} from "@ts-gql/tag";
import {
QueryHookOptions as _QueryHookOptions,
Expand Down Expand Up @@ -143,19 +143,15 @@ export function useMutation<

type KnownKeysWhichAreQueries<
T extends Record<string, TypedDocumentNode<BaseDocumentTypes>>
> = {
[K in keyof T]: string extends K
> = Values<{
[K in keyof T as string extends K
? never
: number extends K
? never
: T[K] extends TypedDocumentNode<BaseTypedQuery>
? K
: never;
} extends { [_ in keyof T]: infer U }
? {} extends U
? never
: U
: never;
: K]: T[K] extends TypedDocumentNode<BaseTypedQuery> ? K : never;
}>;

type Values<T> = T[keyof T];

type RefetchQueryDescription<
TTypedDocumentNode extends TypedDocumentNode<BaseTypedMutation>
Expand Down
62 changes: 31 additions & 31 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"resolveJsonModule": true,
/* Advanced Options */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */,
"skipLibCheck": true
"skipLibCheck": true,
"useUnknownInCatchVariables": false
}
}

0 comments on commit 56aedff

Please sign in to comment.