Skip to content

Ensure cyclic aliases are serialized with a scope reference #930

Closed

Description

@ssalbdivad

Currently, because JSON for a cyclic type references only its alias like $a, if two scopes had differing definitions for the same cyclic alias, caching could break.

Really this should use the id that is precomputed when parsing a node, but I want to ensure that is done in a way that doesn't arbitrarily introduce unnecessary barriers to serialization.

Maybe scopes should should have a globally unique id, then an alias could be ${scodeId}$${alias} or similar.

Failing test case:

				it("intersect cyclic reference with repeat name", () => {
					const types = scope({
						arf: {
							a: "bork"
						},
						bork: {
							b: "arf&bork"
						}
					}).export()

					const resolveRef: string = (
						types.bork.raw.firstReferenceOfKindOrThrow("alias").json as any
					).resolve

					attest(types.bork.json).snap({
						required: [
							{ key: "b", value: { resolve: resolveRef, alias: "$arf&bork" } }
						],
						domain: "object"
					})

					attest(types.arf.json).snap({
						required: [
							{
								key: "a",
								value: types.bork.json
							}
						],
						domain: "object"
					})

					attest(types.arf({ a: { b: {} } }).toString())
						.snap(`a.b.a must be { b: arf&bork } (was missing)
		a.b.b must be arf&bork (was missing)`)
				})

Activity

  1. moved this from To do to Backlog in arktypeioon May 2, 2024
  2. moved this from Backlog to Implemented in arktypeioon Jun 7, 2024
  3. moved this from Implemented to Backlog in arktypeioon Jun 8, 2024
  4. ssalbdivad commented on Nov 18, 2026

    @ssalbdivad
    MemberAuthor

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

  5. 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