Skip to content

Failing validation #1367

Closed
Closed

Description

@Stadly

Report a bug

🔎 Search Terms

validation fail

🧩 Context

  System:
    OS: Linux 5.15 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
    CPU: (16) x64 Intel(R) Xeon(R) W-11955M CPU @ 2.60GHz
    Memory: 3.26 GB / 15.23 GB
    Container: Yes
    Shell: 5.2.15 - /bin/bash
  Binaries:
    Node: 20.18.3 - /usr/local/bin/node
    Yarn: 1.22.22 - /usr/local/bin/yarn
    npm: 10.8.2 - /usr/local/bin/npm
  npmPackages:
    @ark/schema:  0.44.4 
    @ark/util:  0.44.4 
    arktype: ^2.1.9 => 2.1.9 
    typescript: ^5.5.4 => 5.6.2 

🧑‍💻 Repro

const componentModule = type.module({
  container: {
    type: "'container'",
    content: "component",
  },

  flexbox: {
    type: "'flexbox'",
    items: "component",
  },

  tabsItem: {
    id: "string",
    title: "component",
    content: "component",
  },
  tabs: {
    type: "'tabs'",
    items: "tabsItem[]",
  },

  singleComponent: "string | flexbox | tabs",
  component: "singleComponent | singleComponent[]",
});
const componentSchema = componentModule.component;

const component = {
  type: "tabs",
  items: [
    {
      id: "tab-id",
      title: "tab-title",
      content: [],
    },
  ],
};

componentSchema(component);

Here is the validation summary:

must be a string or an array (was {"type":"tabs","items":[{"id":"tab-id","title":"tab-title","content":[]},"tab-title"]}), items must be a string (was an object), items.items must be an object or an array (was missing), items[0] must be items[0] must be a string (was an object) or items[0].items must be an object or an array (was missing) (was {"id":"tab-id","title":"tab-title","content":[]}) or items[1] must be an object (was a string)

Very strange stuff. Validation succeeds if I for example:

  • Remove the container type alias.
  • Rename flexbox.items to flexbox.foo.
  • Rename tabs.items to tabs.foo.
  • Change items[0].title to [].

Activity

  1. added
    bug
    on Mar 12, 2025
  2. Stadly commented on Mar 12, 2025

    @Stadly
    Author

    When I use this data instead:

    const component = {
      type: "tabs",
      items: [
        {
          id: "tab-id",
          title: "tab-title",
          content: "tab-content",
        },
      ],
    };

    I get this error:

    TypeError: Cannot use 'in' operator to search for 'content' in tab-title
        at RequiredNode.traverseApply (arktype.js?v=deb41546:1981:20)
        at StructureNode._traverse (arktype.js?v=deb41546:4404:25)
        at StructureNode.traverseApply (arktype.js?v=deb41546:4396:62)
        at IntersectionNode.traverseApply (arktype.js?v=deb41546:2796:24)
        at arktype.js?v=deb41546:4032:64
        at traverseKey (arktype.js?v=deb41546:493:18)
        at SequenceNode.traverseApply (arktype.js?v=deb41546:4032:9)
        at StructureNode._traverse (arktype.js?v=deb41546:4414:25)
        at StructureNode.traverseApply (arktype.js?v=deb41546:4396:62)
        at IntersectionNode.traverseApply (arktype.js?v=deb41546:2796:24)
    
  3. ssalbdivad commented on Mar 12, 2025

    @ssalbdivad
    Member

    This is likely a duplicate of #1188 so I'm going to close it and add your repro there so we can be sure we add a test case and fix it.

    I'd guess the same jitless workaround is likely to help here as well.

  4. moved this from To do to Done (merged or closed) in arktypeioon Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

  • Status
    Done (merged or closed)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions