Closed smolattack closed 5 months ago
Integrating external concerns like custom error messages with a type system is a really tricky problem, and the solution I came up with for alpha
really missed the mark. I'd recommend adding the problems directly like this:
import { type, scope } from 'arktype';
const emailValidations = scope({
hasADomain: type([
'string',
'=>',
(s, problems) =>
s.includes('@') || !problems.mustBe('a valid email with a domain'),
]),
domainIsValid: type([
'string',
'=>',
(s, problems) => s.endsWith('.com') || !problems.mustBe('a valid domain'),
]),
all: 'hasADomain&domainIsValid',
}).compile();
export const email = emailValidations.all;
export const { data, problems } = email('should give a list of defined errors');
console.log(problems?.summary ?? data);
Aptly, I was actually working on metadata intersections on beta
when you logged this issue. I'll update the title and use this issue to track that work getting merged and that when it does, your original definition will work as expected ⛵
Report a bug
🔎 Search Terms
custom error
🧩 Context
🧑💻 Repro
console shows
But I expect it to show
https://stackblitz.com/edit/arktype-bug-2d9kpj?devToolsHeight=33&file=demo.ts