Skip to content

Commit

Permalink
Fix OptionGroup type now that schema has more properties (#1487)
Browse files Browse the repository at this point in the history
Now it's actually based on keys defined in the groups array, which is more appropriate, rather than assuming "all required props."
This is possible by switching the groups type to a satisfies clause, which wasn't available when the code was first written.
  • Loading branch information
CarsonF authored Oct 24, 2023
1 parent 6a48547 commit 71e27f6
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import onFieldChange from 'final-form-calculate';
import { camelCase } from 'lodash';
import { DateTime } from 'luxon';
import { useMemo, useState } from 'react';
import { RequiredKeysOf } from 'type-fest';
import type { ProgressReportVarianceExplanationReasonOptions as ReasonOptions } from '~/api/schema.graphql';
import { canEditAny } from '~/common';
import {
Expand All @@ -23,9 +22,11 @@ import { VarianceExplanation } from '../../../Detail/VarianceExplanation/Varianc
import { StepComponent } from '../step.types';
import { ExplainProgressVarianceDocument } from './ExplanationOfProgress.graphql';

type OptionGroup = RequiredKeysOf<ReasonOptions>;
type OptionGroup = typeof groups extends Array<infer T> ? T : never;

const groups: OptionGroup[] = ['behind', 'onTime', 'ahead'];
const groups = ['behind', 'onTime', 'ahead'] satisfies Array<
keyof ReasonOptions
>;

const decorators: Array<Decorator<FormShape>> = [
onFieldChange({
Expand Down

0 comments on commit 71e27f6

Please sign in to comment.