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
21 changes: 20 additions & 1 deletion ark/schema/__tests__/union.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { attest, contextualize } from "@ark/attest"
import { rootSchema, writeOrderedIntersectionMessage } from "@ark/schema"
import {
Disjoint,
rootSchema,
writeOrderedIntersectionMessage
} from "@ark/schema"

contextualize(() => {
it("binary", () => {
Expand Down Expand Up @@ -96,4 +100,19 @@ contextualize(() => {
writeOrderedIntersectionMessage("string | number", "number | string")
)
})

// https://github.com/arktypeio/arktype/issues/1645
it("disjoints stay Disjoints when map ignores Symbol.species (Hermes)", () => {
Object.defineProperty(Disjoint, Symbol.species, {
get: () => Array,
configurable: true
})
try {
const d = Disjoint.init("domain", "null", "undefined")
attest(d.withPrefixKey("a", "required") instanceof Disjoint).equals(true)
attest(d.invert() instanceof Disjoint).equals(true)
} finally {
delete (Disjoint as any)[Symbol.species]
}
})
})
10 changes: 8 additions & 2 deletions ark/schema/shared/disjoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,17 @@ export class Disjoint extends Array<DisjointEntry> {
}

withPrefixKey(key: PropertyKey, kind: Prop.Kind): Disjoint {
return this.map(entry => ({
const result = this.map(entry => ({
...entry,
path: [key, ...entry.path],
optional: entry.optional || kind === "optional"
})) as Disjoint
})) as DisjointEntry[]

// same Hermes workaround as invert
// https://github.com/arktypeio/arktype/issues/1645
if (!(result instanceof Disjoint)) return new Disjoint(...result)

return result
}

toNeverIfDisjoint(): BaseRoot {
Expand Down
2 changes: 1 addition & 1 deletion ark/type/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ export class InternalScope<$ extends {} = {}> extends BaseScope<$> {
new InternalScope(def, config)) as never

static module: ModuleParser = ((def: Dict, config: ArkScopeConfig = {}) =>
this.scope(def as never, config).export()) as never
InternalScope.scope(def as never, config).export()) as never
}

export const scope: ScopeParser = Object.assign(InternalScope.scope, {
Expand Down
Loading