Skip to content

Commit

Permalink
Simplify types for requiring or not requiring variables
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatown committed Apr 22, 2022
1 parent 0e3e2f5 commit d002ea4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/little-dodos-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ts-gql/apollo": patch
---

Simplified types for requiring or not requiring variables
10 changes: 1 addition & 9 deletions packages/apollo/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,11 @@ type FetchResult<
context?: C;
};

export type RequiredKeys<T> = {
[K in keyof T]: {} extends Pick<T, K> ? never : K;
} extends { [_ in keyof T]: infer U }
? {} extends U
? never
: U
: never;

export type HasRequiredVariables<
TTypedDocumentNode extends TypedDocumentNode<BaseOperations>,
RequiredResult,
OptionalResult
> = RequiredKeys<OperationVariables<TTypedDocumentNode>> extends never
> = {} extends OperationVariables<TTypedDocumentNode>
? OptionalResult
: RequiredResult;

Expand Down

0 comments on commit d002ea4

Please sign in to comment.