Skip to content

Unable to directly configure top-level intersection error message #1412

Closed

Description

@ssalbdivad
import { type } from "arktype";

const Thing = type("string.email > 0").configure({
  message: "Email is not valid",
});

// standard bulleted message- config seemingly not applied
const out = Thing("");

Playground: https://arktype.io/playground?code=import%2520%257B%2520type%2520%257D%2520from%2520%2522arktype%2522%250A%250Aconst%2520Thing%2520%253D%2520type%28%2522string.email%2520%253E%25200%2522%29.configure%28%257B%250A%2509message%253A%2520%2522Email%2520is%2520not%2520valid%2522%250A%257D%29%250A%250A%252F%252F%2520standard%2520bulleted%2520message-%2520config%2520seemingly%2520not%2520applied%250Aconst%2520out%2520%253D%2520Thing%28%2522%2522%29%250A

This doesn't work because an intersection error is built from a dynamic list of failures, so metadata from the node is never applied to the error.

Workaround:

Configure intersection errors globally or at a scope-level:

const { type } = scope(
  {},
  {
    intersection: {
      message: (ctx) => {
        if (
          ctx.flat.every(
            (e, i) =>
              i === ctx.flat.length - 1 || e.message === ctx.flat[i + 1].message
          )
        ) {
          return ctx.flat[0].message;
        }
        return ctx.problem;
      },
    },
  }
);

const Thing = type("string.email > 0").configure({
  message: "Email is not valid",
});

const out = Thing("");

// Email is not valid
console.log(out.summary);

Playground: https://arktype.io/playground?code=import%2520%257B%2520scope%2520%257D%2520from%2520%2522arktype%2522%250A%250Aconst%2520%257B%2520type%2520%257D%2520%253D%2520scope%28%250A%2509%257B%257D%252C%250A%2509%257B%250A%2509%2509intersection%253A%2520%257B%250A%2509%2509%2509message%253A%2520%28ctx%29%2520%253D%253E%2520%257B%250A%2509%2509%2509%2509if%2520%28%250A%2509%2509%2509%2509%2509ctx.flat.every%28%250A%2509%2509%2509%2509%2509%2509%28e%252C%2520i%29%2520%253D%253E%250A%2509%2509%2509%2509%2509%2509%2509i%2520%253D%253D%253D%2520ctx.flat.length%2520-%25201%2520%257C%257C%2520e.message%2520%253D%253D%253D%2520ctx.flat%255Bi%2520%252B%25201%255D.message%250A%2509%2509%2509%2509%2509%29%250A%2509%2509%2509%2509%29%2520%257B%250A%2509%2509%2509%2509%2509return%2520ctx.flat%255B0%255D.message%250A%2509%2509%2509%2509%257D%250A%2509%2509%2509%2509return%2520ctx.problem%250A%2509%2509%2509%257D%250A%2509%2509%257D%250A%2509%257D%250A%29%250A%250Aconst%2520Thing%2520%253D%2520type%28%2522string.email%2520%253E%25200%2522%29.configure%28%257B%250A%2509message%253A%2520%2522Email%2520is%2520not%2520valid%2522%250A%257D%29%250A%250Aconst%2520out%2520%253D%2520Thing%28%2522%2522%29%250A

Activity

  1. moved this from To do to Backlog in arktypeioon Apr 14, 2025
  2. robin-blanchard commented on Jul 16, 2025

    @robin-blanchard

    Related: #1479

  3. ssalbdivad commented on Nov 18, 2026

    @ssalbdivad
    MemberAuthor

    Fixed in 3.0.0-beta.0 (#1728). Try it with npm i arktype@next.

  4. moved this from Backlog to Done (merged or closed) in arktypeioon Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      Done (merged or closed)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions