Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When I use when condition repeatedly, I get an Overload error. #2159

Open
zbkmr opened this issue Jan 4, 2024 · 3 comments
Open

When I use when condition repeatedly, I get an Overload error. #2159

zbkmr opened this issue Jan 4, 2024 · 3 comments

Comments

@zbkmr
Copy link

zbkmr commented Jan 4, 2024

@jquense I wasn't sure if the issue was related to this or not.

#1924

I have problems every time I add the second when condition.

const validations: Yup.ObjectSchema<DetailedFormProps> = Yup.object()
  .shape(
    {
      startDate: Yup.date()
        .nullable()
        .when('endDate', {
          is: (endDate: Date) => endDate,
          then: () =>
            Yup.date().required(
              'accounts_accountActivities_startDateEndDateSelection_errorMessage'
            ),
          otherwise: () => Yup.date(),
        })
        .defined()
        .when('endDate', (endDate: Date, schema) =>
          schema
            .test(
              'is-three-months-between-dates',
              'accounts_accountActivities_startDateEndDateRange_errorMessage',
              (startDate?: Date | null) =>
                startDate && endDate ? IsDateDifferenceMoreThanMonths(startDate, endDate, 12) : true
            )
            .max(endDate || new Date(), 'accounts_accountActivities_startDateEndDate_errorMessage')
        ),

MY error message

error TS2769: No overload matches this call.
  Overload 1 of 4, '(keys: string | string[], builder: ConditionBuilder<DateSchema<Date | null, AnyObject, undefined, "">>): DateSchema<Date | null, AnyObject, undefined, "">', gave the following error.
    Argument of type '(endDate: Date, schema: DateSchema<Date | null, AnyObject, undefined, "">) => DateSchema<Date | null, AnyObject, undefined, "">' is not assignable to parameter of type 'ConditionBuilder<DateSchema<Date | null, AnyObject, undefined, "">>'.
      Types of parameters 'endDate' and 'values' are incompatible.
        Type 'any[]' is missing the following properties from type 'Date': toDateString, toTimeString, toLocaleDateString, toLocaleTimeString, and 38 more.
  Overload 2 of 4, '(keys: string | string[], options: ConditionConfig<DateSchema<Date | null, AnyObject, undefined, "">>): DateSchema<Date | null, AnyObject, undefined, "">', gave the following error.
    Argument of type '(endDate: Date, schema: DateSchema<Date | null, AnyObject, undefined, "">) => DateSchema<Date | null, AnyObject, undefined, "">' is not assignable to parameter of type 'ConditionConfig<DateSchema<Date | null, AnyObject, undefined, "">>'.
      Property 'is' is missing in type '(endDate: Date, schema: DateSchema<Date | null, AnyObject, undefined, "">) => DateSchema<Date | null, AnyObject, undefined, "">' but required in type 'ConditionConfig<DateSchema<Date | null, AnyObject, undefined, "">>'.
export interface DetailedFormProps {
  startDate: Date | null;
  // endDate: Date | null;
  /*  minimumAmount: string;
  maximumAmount: string;
  explanation: string;
  sort: DictionaryLine | null;
  transactionType: DictionaryLine | null;
  channelCode: DictionaryLine | null;
  operationType: DictionaryLine | null; */
}

Thanks in advance for the answer.

@yamanidev
Copy link

I am having a similar issue. Any updates?

@ricohumme
Copy link

same here. Seems that the ConditionBuilder is unaware of the ConditionConfig

@remstone7
Copy link

bump, ran into same issue as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants