Skip to content

jsonSchemaToType: { type: "string", enum: [...] } throws "Intersection of string and object results in an unsatisfiable type" #1595

@graffhyrum

Description

@graffhyrum

Bug Report

jsonSchemaToType from @ark/json-schema throws a ParseError when given a schema that combines type: "string" with enum. This is a common JSON Schema pattern (the type annotation is redundant but valid per spec when all enum values are strings).

Package

@ark/json-schema v0.0.4

Repro

import { jsonSchemaToType } from "@ark/json-schema"

// ✅ works
jsonSchemaToType({ type: "string" })

// ✅ works
jsonSchemaToType({ enum: ["stable", "latest"] })

// ❌ throws: ParseError: Intersection of string and object results in an unsatisfiable type
jsonSchemaToType({ type: "string", enum: ["stable", "latest"] })

// ❌ also throws (default + enum + type)
jsonSchemaToType({ type: "string", enum: ["stable", "latest"], default: "latest" })

// ❌ also throws when nested inside an object property
jsonSchemaToType({
  type: "object",
  properties: {
    mode: { type: "string", enum: ["append", "replace"] }
  }
})

Expected behavior

{ type: "string", enum: ["stable", "latest"] } should produce the equivalent of type("'stable' | 'latest'"). Per JSON Schema spec, when type and enum are combined, the type annotation is informational — the enum constraint already restricts the valid values.

Actual behavior

ParseError: Intersection of string and object results in an unsatisfiable type
    at throwError (node_modules/@ark/util/out/errors.js:5:11)
    at applyMorphsAtPath (node_modules/@ark/schema/out/shared/traversal.js:184:28)
    at applyQueuedMorphs (node_modules/@ark/schema/out/shared/traversal.js:166:22)
    at finalize (node_modules/@ark/schema/out/shared/traversal.js:109:18)
    at <anonymous> (node_modules/@ark/json-schema/out/object.js:103:20)

The library appears to process type: "string" and enum as separate constraints and then intersect them, producing string & object = unsatisfiable, rather than recognising that enum with all-string values is already a string subtype.

Context

Encountered while trying to use jsonSchemaToType with the Claude Code settings JSON Schema, which uses { type: "string", enum: [...] } for several properties (autoUpdatesChannel, effortLevel, forceLoginMethod, spinnerVerbs.mode, teammateMode).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    To do

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions