Skip to content

How to validate map with dynamic keys (FormikErrors<T>) #3255

Answered by tparvi
tparvi asked this question in Q&A
Discussion options

You must be logged in to vote

Got some help and it seems I need to do the following to get around TS error:

  function validate(
    values: WeekdayMap<Schedule>
  ): FormikErrors<WeekdayMap<Schedule>> {
    // Without this TS says : Type '{ foo: string; }' is not assignable to type 'string'
    const Monday = "Monday" as Day;
    return {
      [Monday]: {
        foo: "I want to return error for this field"
      }
    };
  }

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by tparvi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant