Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions ark/schema/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,14 @@ const precompile = (references: readonly BaseNode[]): void =>

const bindPrecompilation = (
references: readonly BaseNode[],
precompiler: CompiledFunction<() => PrecompiledReferences>
precompiler: CompiledFunction<() => PrecompiledReferences>,
owningScope?: BaseScope
): void => {
const precompilation = precompiler.write(rootScopeFnName, 4)
const compiledTraversals = precompiler.compile()()

for (const node of references) {
if (node.precompilation) {
if (node.precompilation && (!owningScope || node.$ !== owningScope)) {
// if node has already been bound to another scope or anonymous type, don't rebind it
continue
}
Expand Down Expand Up @@ -642,7 +643,7 @@ export abstract class BaseScope<$ extends {} = {}> {
if (!this.resolvedConfig.jitless) {
const precompiler = precompileReferences(this.references)
this.precompilation = precompiler.write(rootScopeFnName, 4)
bindPrecompilation(this.references, precompiler)
bindPrecompilation(this.references, precompiler, this)
}
this.resolved = true
}
Expand Down
25 changes: 25 additions & 0 deletions ark/type/__tests__/realWorld.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,31 @@ date3 must be a parsable date (was "")`)
attest(result).equals(component)
})

// https://github.com/arktypeio/arktype/issues/1362
it("cyclic discriminated union with private alias", () => {
const componentModule = type.module({
"#tabsItem": {
id: "string",
title: "component",
content: "component"
},
tabs: {
type: "'tabs'",
items: "tabsItem[]"
},
component: "string | tabs"
})
const componentSchema = componentModule.component

const component: typeof componentSchema.infer = {
type: "tabs",
items: []
}

// previously threw "TypeError: this.tabs1Apply is not a function"
attest(componentSchema(component)).equals(component)
})

// https://github.com/arktypeio/arktype/issues/1209
it("cyclic discriminated union issue 3", () => {
const $ = scope({
Expand Down
Loading