fabian-hiller / valibot

The modular and type safe schema library for validating structural data 🤖
https://valibot.dev
MIT License
5.6k stars 169 forks source link

Modify tupleAsync schema items reference more precise #649

Closed chimame closed 3 weeks ago

chimame commented 3 weeks ago

Overview

The items specified when generating a tupleAsync schema are curried. So I wrote this fix.

Details

This change is for the same reason as the previous change to the variant schema. #600

I have created code that reproduces this issue.

import * as v from 'valibot';

const Schema = v.tupleAsync([v.number(), v.string()]);

const convertSchema = {
  ...Schema,
  items: Schema.items.map((item) => {
    v.pipeAsync(
      v.unknown(),
      v.transform((output) => {
        console.log('not execute')
        return output == null ? 0 : output
      }),
      item,
    )
  })
}

console.log('start parse')
const result = await v.safeParseAsync(convertSchema, [null, 'test']);
console.log('end parse')

console.log(result); // <-- parse error
fabian-hiller commented 3 weeks ago

Thank you! I will review and merge it soon.

fabian-hiller commented 3 weeks ago

v0.32.0 is available