Skip to content

RegExpExecArray does not match ArraySchema #946

Open
@Kritolan

Description

I just want to parse a specific value from a string using RegExp. This works, but TS complains about types.

import * as v from 'valibot';

const Schema = v.pipe(
  v.string(),
  // correct string - 2024.01.30
  v.transform(value => /^(\d{4})\.\d{2}\.\d{2}$/.exec(value)),
  v.array(v.string()),
  v.length(2),
  v.transform(value => Number(value[1])),
);

const result = v.safeParse(Schema, '2024.01.30');
console.log(result);

Metadata

Labels

questionFurther information is requested

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions