Skip to content

Commit

Permalink
feature(conditionals): added jsdocs for ConditionalConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
scottrippey committed Jan 17, 2024
1 parent 77ade33 commit d09ece4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 10 additions & 0 deletions packages/groq-builder/src/commands/conditional-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ export type ConditionalConfig<
TKey extends string = string,
TIsExhaustive extends boolean = boolean
> = {
/**
* If using multiple conditions in a single projection,
* each condition must have a unique key.
* This key is not used in the resulting query, and can be anything.
*/
key: TKey;
/**
* If the conditional statements cover all possible scenarios,
* then setting `isExhaustive` to `true` will ensure stronger types,
* and can throw runtime errors if none of the conditions are satisfied.
*/
isExhaustive: TIsExhaustive;
};
11 changes: 7 additions & 4 deletions packages/groq-builder/src/commands/conditionalByType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GroqBuilder } from "../groq-builder";
import { RootConfig } from "../types/schema-types";
import { ExtractTypeNames, RootConfig } from "../types/schema-types";
import { ResultItem } from "../types/result-types";
import {
ExtractConditionalByTypeProjectionResults,
Expand All @@ -18,9 +18,12 @@ declare module "../groq-builder" {
TRootConfig
>,
TKey extends string = "[ByType]",
TIsExhaustive extends boolean = TConditionalProjections extends Required<
ConditionalByTypeProjectionMap<ResultItem<TResult>, TRootConfig>
>
/**
* Did we supply a condition for all possible _type values?
*/
TIsExhaustive extends boolean = ExtractTypeNames<
ResultItem<TResult>
> extends keyof TConditionalProjections
? true
: false
>(
Expand Down

0 comments on commit d09ece4

Please sign in to comment.