valibot: TS error when using custom()
The property schema: ‘object’ gives me a TS error and I can’t put it to work.
const FormSchema = v.object(
{
dataFimValidadeFim: v.nullable(
v.optional(v.coerce(v.date('validation.date'), (input) => new Date(input as number | string | Date))),
),
dataFimValidadeInicio: v.nullable(
v.optional(v.coerce(v.date('validation.date'), (input) => new Date(input as number | string | Date))),
),
dataInicioValidadeFim: v.nullable(
v.optional(v.coerce(v.date('validation.date'), (input) => new Date(input as number | string | Date))),
),
dataInicioValidadeInicio: v.nullable(
v.optional(v.coerce(v.date('validation.date'), (input) => new Date(input as number | string | Date))),
),
dataPedidoFim: v.nullable(
v.optional(v.coerce(v.date('validation.date'), (input) => new Date(input as number | string | Date))),
),
dataPedidoInicio: v.nullable(
v.optional(v.coerce(v.date('validation.date'), (input) => new Date(input as number | string | Date))),
),
idEstado: v.optional(v.coerce(v.string(), String)),
idInterno: v.optional(v.coerce(v.string(), String)),
identificador: v.optional(v.string()),
nome: v.optional(v.string()),
},
[
v.custom((inputs) => {
if (inputs.dataInicioValidadeInicio && inputs.dataInicioValidadeFim) {
if (dateRangeValidator(inputs.dataInicioValidadeInicio, inputs.dataInicioValidadeFim)) {
throw new ValiError([
{
input: inputs.dataInicioValidadeInicio,
message: 'validation.minDateExceeded',
origin: 'value',
reason: 'date',
validation: 'custom',
path: [
{
input: inputs,
key: 'dataInicioValidadeInicio',
schema: 'object', <--- Object literal may only specify known properties, and 'schema' does not exist in type 'PathItem'.
value: inputs.dataInicioValidadeInicio,
},
],
},
]);
}
}
return true;
}),
],
);
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 28 (14 by maintainers)
I agree, let’s do the following, I’ll close this issue and open a new one with a recap of this one.
I’ll check it ASAP and let you know.
I’ll open one issue latter today.
Feel free to create a new issue (or PR) to add an
itemsaction in the next weeks.Thanks, I’ll play with it again.
I am working on it and will probably add it later today.
You are right. I will probably add it today or tomorrow. I will ping you then.
Oh, that’s what I need, I thought that the
customwas deprecated. Thanks. I’ll play a bit with the current state of the lib.Please update this issue when this action gets done.
Although it’s not recommended, I’ll let
v.customwiththrowas it is working as I need, I’ll come here again when the rewrite is done to update it. And perhaps close the issue then with a solution.In summary, I would like to have:
otherNationalities.2.I think so, in my current implementation, this is important to select the duplicated option, and with the code that I’ve shared here, it works.
Those are great news, I’m looking forward to testing it.