Skip to content

Circular scope compilation bug #1188

Closed

Description

@TizzySaurus

Report a bug

🔎 Search Terms

circular scope, scope compilation bug, Apply is not a function.

🧩 Context

  • ArkType version: 2.0.0-rc.21
  • TypeScript version (5.1+): Version 5.7.0-dev.20241002
  • Other context you think may be relevant (JS flavor, OS, etc.): N/A

🧑‍💻 Repro

Minimum repro:

import { scope, type } from "arktype"

const $ = scope({
    Foo: {
        "oneOf?": "Bar[]" // NB: don't get the error if this is not an array
    },
    Bar: "Foo"
}).export()

const baz = $.Bar.pipe((_: object): type.Any | undefined => {
    console.log("this never gets logged since pipe isn't entered")
    return type("string")
})

const r = baz({ oneOf: [{}] }) // throws "TypeError: this.Foo1Apply is not a function"
console.log(r)

Activity

  1. added
    bug
    on Oct 30, 2024
  2. Kal-Aster commented on Dec 18, 2024

    @Kal-Aster

    I encountered this right now 💀

    Meanwhile is there any workaround?

  3. added
    confirmed
    on Jan 3, 2025
  4. ssalbdivad commented on Jan 26, 2025

    @ssalbdivad
    Member

    As a temporary workaround, you can try passing { jitless: true } to your scope since this issue seems specific to precompilation:

    const types = scope(
    	{
    		Foo: {
    			"oneOf?": "Bar[]"
    		},
    		Bar: "Foo"
    	},
    	{
    		jitless: true
    	}
    ).export()
  5. ssalbdivad commented on Mar 12, 2025

    @ssalbdivad
    Member

    Adding the repro from #1367 which I've closed as a likely duplicate (should be added as a test case when this is addressed):

    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);
  6. Christopher96u commented on Apr 10, 2025

    @Christopher96u

    As a temporary workaround, you can try passing { jitless: true } to your scope since this issue seems specific to precompilation:

    const types = scope(
    {
    Foo: {
    "oneOf?": "Bar[]"
    },
    Bar: "Foo"
    },
    {
    jitless: true
    }
    ).export()

    Hi David, I'm using jitless 'true', but having weird issues like the author of that repro. It looks I need to hold off my migration from zod to Arktype using until this bug is fixed. I'm following an implementation like that with cyclic types rendering cms components. I need to comment the cyclic types to make it work, otherwise it throws error(The ... is not a function). Otherwise I got this error .

    Image

  7. moved this from Backlog to Implemented in arktypeioon Apr 16, 2025
  8. moved this from Implemented to Done (merged or closed) in arktypeioon Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugconfirmed

Type

No type

Projects

  • Status
    Done (merged or closed)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions