For now, findItem returns the input type event when trying to narrow the typing using type predicates. For example :
import * as v from 'valibot';
type Animal = 'cat' | 'dog';
const isAnimal = (v: string): v is Animal => v === 'cat' || v === 'dog';
const schema = v.pipe(
v.array(v.string()),
v.findItem(isAnimal)
)
const animal = v.parse(schema, ['apple', 'cat', 'screw']);
// animal is type string | undefined
It would be cool to get better type narrowing. For now, you have to do this, which feels weird given that findItem exists :
For now, findItem returns the input type event when trying to narrow the typing using type predicates. For example :
It would be cool to get better type narrowing. For now, you have to do this, which feels weird given that findItem exists :