ciscoheat
ciscoheat
Explore posts from servers
Aarktype
Created by ciscoheat on 5/11/2024 in #questions
Problem with validation in 2.0 dev?
I'm using 2.0.0-dev.11 and cannot figure out why some very basic validation fails. Short example:
import { type } from "arktype";

const nospacePattern = /^\S*$/;

const schema = type({
name: "string",
email: "email",
tags: "(string>=2)[]>=3",
score: "integer>=0",
"date?": "Date",
"nospace?": nospacePattern,
extra: "string|null",
});

const data = {
name: "Ok",
email: "",
tags: ["AB", "B"],
score: -1,
date: undefined,
nospace: "One space",
};

const out = schema(data);

console.log("nospace matches:", nospacePattern.test(data.nospace));

if (out instanceof type.errors) {
console.log(out.summary);
} else {
console.log(out);
}
import { type } from "arktype";

const nospacePattern = /^\S*$/;

const schema = type({
name: "string",
email: "email",
tags: "(string>=2)[]>=3",
score: "integer>=0",
"date?": "Date",
"nospace?": nospacePattern,
extra: "string|null",
});

const data = {
name: "Ok",
email: "",
tags: ["AB", "B"],
score: -1,
date: undefined,
nospace: "One space",
};

const out = schema(data);

console.log("nospace matches:", nospacePattern.test(data.nospace));

if (out instanceof type.errors) {
console.log(out.summary);
} else {
console.log(out);
}
The output I get from running this is:
nospace matches: false
email must be a valid email (was "")
extra must be a string or null (was missing)
date must be a Date (was undefined)
nospace matches: false
email must be a valid email (was "")
extra must be a string or null (was missing)
date must be a Date (was undefined)
I'd expected errors for score, nospace, tags and maybe tags[1] as well. Anything very simple I'm missing?
16 replies
Aarktype
Created by ciscoheat on 12/23/2023 in #questions
Array error message
Hello, I think I found an inconsistency in array errors: https://stackblitz.com/edit/vy55da?file=type.ts The tags error is: tags must be at least 3 characters (was 2) But should probably not be characters, but something like items.
3 replies