Skip to content

Validation transformer throwing TS error on nested data access #1020

Closed Answered by fabian-hiller
m-kutnik asked this question in Q&A
Discussion options

You must be logged in to vote

Without further investigation, it appears that TS has problems resolving a generic schema in this case. In the long run, we should investigate whether this is due to our implementation or a limitation of TS.

A simple workaround is to keep only the input (and optionally the output) generic, but not the pass schema itself:

const unwrapResponse = <TInput, TOutput>(
  schema: v.GenericSchema<TInput, TOutput>
) =>
  v.pipe(
    v.object({
      body: v.object({
        data: schema,
      }),
    }),
    v.transform((input) => {
      return input.body.data;
    })
  );

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@m-kutnik
Comment options

Answer selected by m-kutnik
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
enhancement New feature or request question Further information is requested priority This has priority
2 participants