Skip to content

fix(schema): convert what JSON Schema can't represent in ~standard.jsonSchema instead of throwing - #1694

Merged
ssalbdivad merged 1 commit into
mainfrom
standard-json-schema-fallback
Oct 13, 2026
Merged

ssalbdivad merged 1 commit into
mainfrom
standard-json-schema-fallback

Conversation

@ssalbdivad

Copy link
Copy Markdown
Member

~standard.jsonSchema.input/output now throw if and only if an option is unsupported (a target other than draft-2020-12 or draft-07), and convert unknown or unrepresentable data to {}. This matches the semantics the Standard Tool draft (standard-schema/standard-schema tool branch) relies on: a tool's input schema is what a model is shown, so a converter that throws on a .narrow() or a bigint key leaves a tool that can't be described at all.

Where JSON Schema can't represent part of a type, the converter keeps the part it can:

  • a predicate, a second pattern, a Date bound or an array's non-index props is dropped from the schema it constrains
  • bigint, symbol, a non-JSON unit like undefined and any prototype other than Array become {}
  • a variadic tuple with postfix elements keeps its prefix and minItems, but not its items
  • a default that isn't JSON is omitted

Only the default fallbacks (which throw) are replaced, so fallbacks from the scope's toJsonSchema config or from libraryOptions still take precedence. toJsonSchema() itself still throws by default.

A defaultValue fallback can now return undefined to omit the default rather than writing default: undefined.

🤖 Generated with Claude Code

…onSchema instead of throwing

Standard JSON Schema converters now throw if and only if an option is
unsupported, like a target other than draft-2020-12 or draft-07, and
convert unknown or unrepresentable data to {}. That is the contract
Standard Tool builds on: a tool's input schema is what a model is shown,
so a converter that throws on a narrow or a bigint key leaves a tool that
can't be described at all.

Where JSON Schema can't represent part of a type, ~standard.jsonSchema
keeps the part it can:

- a predicate, a second pattern, a Date bound or an array's non-index
  props is dropped from the schema it constrains
- bigint, symbol, a non-JSON unit like undefined and any prototype other
  than Array become {}
- a variadic tuple with postfix elements keeps its prefix and minItems,
  but not its items
- a default that isn't JSON is omitted

Only the default fallbacks, which throw, are replaced, so fallbacks from
the scope's toJsonSchema config or from libraryOptions still win.
toJsonSchema() itself still throws by default.

A defaultValue fallback can now return undefined to omit the default,
rather than writing default: undefined.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Standard converter no longer throws on unrepresentable data: ~standard.jsonSchema.input/output now route through a new toStandardJsonSchema helper in ark/schema/roots/root.ts:728 that merges the scope/libraryOptions config, then swaps only the default throwing fallbacks (matched by identity against ToJsonSchema.defaultConfig.fallback) for the lenient standardFallback handlers. Explicitly configured fallbacks still win.
  • Lenient fallbacks added: ark/schema/shared/toJsonSchema.ts:56 adds standardFallback, where most codes keep ctx.base, defaultValue returns undefined, and arrayPostfix keeps the representable prefix (prefixItems for draft-2020-12, items array for draft-07) while dropping the variadic. The defaultValue handler type is widened to JsonSchema | undefined.
  • Defaults can now be omitted: ark/schema/roots/root.ts:215, sequence.ts:546, and structure.ts:850 skip writing default when the fallback returns undefined, instead of emitting default: undefined.
  • Tests: ark/type/__tests__/standardSchema.test.ts covers unrepresentable types collapsing to {}, transform output, the draft-07 postfix prefix, and precedence of configured libraryOptions fallbacks.

I verified the identity-based fallback replacement holds for unconfigured, scope-level, and libraryOptions fallbacks (references are preserved through mergeFallbacks), that the postfix fallback correctly drops the variadic (keeping it would reject valid arrays ending in a postfix element), and that the defaultValue: undefined omission doesn't change toJsonSchema() default behavior. pnpm test (1791 passing) and the type-checked test runs are green.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@ssalbdivad
ssalbdivad merged commit 5aad144 into main Oct 13, 2026
14 checks passed
@ssalbdivad
ssalbdivad deleted the standard-json-schema-fallback branch October 13, 2026 17:04
@github-project-automation github-project-automation Bot moved this from To do to Done (merged or closed) in arktypeio Oct 13, 2026
ssalbdivad added a commit that referenced this pull request Oct 13, 2026
#1694 is already on featherduster as 7d07468, which ports it to
arksets (omitting a default its handler returns undefined for where
ark/sets/toJsonSchema.ts writes one), so main's edits to
structure.ts/sequence.ts and BaseRoot.toResolvedJsonSchema, which
featherduster no longer writes JSON Schema from, resolve to that version.

main replaces writeLlmsTxt.ts with writeMarkdown.ts and moves the keyword
table's data into lib/keywords.ts. featherduster's ArkRegex section is
carried into writeMarkdown's sections, and its keyword table fixes into
keywords.ts: resolving every keyword with ark.export() before reading
resolutions (they build on first reference), skipping a resolution that
is still a parse context, and classifying instanceof keywords by
ecmascriptConstructors/platformConstructors rather than arkPrototypes.
KeywordTable.tsx is main's renderer. llms.txt files are regenerated,
regex's now in the same Markdown form as the others, and AGENTS.md
mentions both ArkRegex's llms.txt and the skill, as does main's new
agents page beside Attest's.

For #1688, main's onlyNamedTestFiles gate supersedes featherduster's
earlier version of the same change, so attest/utils.ts and testFiles take
main's. typecheckRepo takes main's "tsc --incremental", which runs the
same binary as "pnpm tsc" now that there is no tsc script, and testRepo
keeps featherduster's testBuild.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
ssalbdivad added a commit that referenced this pull request Oct 20, 2026
Bumps all publishable packages and documents the changes merged since
2.2.8:

- keep tuple elements around defaults in .in and .out (#1696, @ybai08)
- reject NaN in unions discriminated by typeof (#1702, @thecotne)
- don't treat Object.prototype keys as declared (#1701, @thecotne)
- only emit referenced $defs in toJsonSchema (#1689, fixes #1612,
  #1511 and #1546, @giaBaoJS)
- convert unrepresentable types in ~standard.jsonSchema instead of
  throwing (#1694)
- arkregex: allow } to be escaped (#1691, @cpruijsen)
- attest: onlyNamedTestFiles (#1688)

Also moves attest to TypeScript 7.1's stable native API. Starting with
7.1.0-dev.20261009.1, typescript/unstable/{ast,sync,fs} are exported as
typescript/{ast,sync,fs}, so the published 0.57.0 fails on every current
7.1 build with "Package subpath './unstable/ast' is not defined by
exports". The tsconfig paths aliases for the old specifiers kept
resolving them, so typecheck stayed green while attest crashed at
runtime. They are renamed alongside the imports.

The workspace TypeScript moves to 7.1.0-dev.20261020.3, the latest
nightly (no 7.1 beta is published yet).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
ssalbdivad added a commit that referenced this pull request Oct 20, 2026
Bumps all publishable packages and documents the changes merged since
2.2.8:

- keep tuple elements around defaults in .in and .out (#1696, @ybai08)
- reject NaN in unions discriminated by typeof (#1702, @thecotne)
- don't treat Object.prototype keys as declared (#1701, @thecotne)
- only emit referenced $defs in toJsonSchema (#1689, fixes #1612,
  #1511 and #1546, @giaBaoJS)
- convert unrepresentable types in ~standard.jsonSchema instead of
  throwing (#1694)
- arkregex: allow } to be escaped (#1691, @cpruijsen)
- attest: onlyNamedTestFiles (#1688)

Also moves attest to TypeScript 7.1's native API paths. Starting with
7.1.0-dev.20261009.1, typescript/unstable/{ast,sync,fs} are exported as
typescript/{ast,sync,fs}, so the published 0.57.0 fails on every current
7.1 build with "Package subpath './unstable/ast' is not defined by
exports". The tsconfig paths aliases for the old specifiers kept
resolving them, so typecheck stayed green while attest crashed at
runtime. They are renamed alongside the imports.

The workspace TypeScript moves to 7.1.0-beta, which exports the same
paths.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
ssalbdivad added a commit that referenced this pull request Oct 20, 2026
Bumps all publishable packages and documents the changes merged since
2.2.8:

- keep tuple elements around defaults in .in and .out (#1696, @ybai08)
- reject NaN in unions discriminated by typeof (#1702, @thecotne)
- don't treat Object.prototype keys as declared (#1701, @thecotne)
- only emit referenced $defs in toJsonSchema (#1689, fixes #1612,
  #1511 and #1546, @giaBaoJS)
- convert unrepresentable types in ~standard.jsonSchema instead of
  throwing (#1694)
- arkregex: allow } to be escaped (#1691, @cpruijsen)
- attest: onlyNamedTestFiles (#1688)

Also moves attest to TypeScript 7.1's native API paths. Starting with
7.1.0-dev.20261009.1, typescript/unstable/{ast,sync,fs} are exported as
typescript/{ast,sync,fs}, so the published 0.57.0 fails on every current
7.1 build with "Package subpath './unstable/ast' is not defined by
exports". The tsconfig paths aliases for the old specifiers kept
resolving them, so typecheck stayed green while attest crashed at
runtime. They are renamed alongside the imports.

The workspace TypeScript moves to 7.1.0-beta, which exports the same
paths.
renovate Bot added a commit to cigaleapp/cigale that referenced this pull request Nov 2, 2026
##### [v2.2.9](https://github.com/arktypeio/arktype/blob/HEAD/ark/type/CHANGELOG.md#229)

##### Keep tuple elements around defaults in `.in` and `.out`

Combining a tuple's defaultable elements with its other elements dropped some of them, depending on key order:

```ts
const T = type(["string", "number = 5", "boolean?"])

// was: [string, boolean?]
// now: [string, number?, boolean?]
T.in.expression

// was: number[]
// now: [number, string, ...number[]]
type(["number", "string = 'foo'", "...", "number[]"]).out.expression
```

A bound that narrows two existing length constraints at once also no longer throws "multiple distinct intersection results":

```ts
// was: throws
// now: string == 2
type("1 <= string <= 2").and("string >= 2")
```

Thanks to [@ybai08](https://github.com/ybai08) ([#1696](arktypeio/arktype#1696)).

##### Reject `NaN` in unions discriminated by `typeof`

`number` rejects `NaN`, but compiled unions like `number | null` dropped that check when they discriminated by `typeof`, so `NaN` was only rejected with `jitless` ([#1702](arktypeio/arktype#1702)).

```ts
const T = type("number | null")

// was: NaN
// now: ArkErrors: must be a number (was NaN)
T(NaN)
```

Thanks to [@thecotne](https://github.com/thecotne).

##### Don't treat `Object.prototype` keys as declared

Inherited names like `toString` or `constructor`, and an own `__proto__` key like the one `JSON.parse` creates, were treated as declared keys, so `"+": "delete"` kept them and `"+": "reject"` accepted them ([#1701](arktypeio/arktype#1701)).

```ts
const T = type({ a: "string", "+": "reject" })

// was: { a: "x", constructor: 1 }
// now: ArkErrors: constructor must be removed
T({ a: "x", constructor: 1 })
```

Thanks to [@thecotne](https://github.com/thecotne).

##### Only emit referenced `$defs` in `toJsonSchema`

With `useRefs`, or for a cyclic type, every node a type referenced was written to `$defs`, including discriminated union cases that never appear in the output. Some of those couldn't be converted, so `toJsonSchema()` threw `Unexpected JSON Schema input for structure: {}` ([#1689](arktypeio/arktype#1689), fixes [#1612](arktypeio/arktype#1612), [#1511](arktypeio/arktype#1511) and [#1546](arktypeio/arktype#1546)).

```ts
const T = type.or(
	{ a: type.enumerated("a", "b", "c"), b: "1" },
	{ a: type.enumerated("a", "e", "f"), b: "2" }
)

// was: throws
// now: only the $defs that a $ref points to
T.toJsonSchema({ useRefs: true })
```

Thanks to [@giaBaoJS](https://github.com/giaBaoJS).

##### Convert unrepresentable types in `~standard.jsonSchema` instead of throwing

`~standard.jsonSchema.input` and `.output` now throw only for an unsupported `target`, i.e. one other than `draft-2020-12` or `draft-07`. Parts of a type that JSON Schema can't represent are converted instead ([#1694](arktypeio/arktype#1694)):

- a predicate, a second pattern, a `Date` bound or an array's non-index props is dropped from the schema it constrains
- `bigint`, `symbol`, a non-JSON unit like `undefined` and any prototype other than `Array` become `{}`
- a variadic tuple with postfix elements keeps its prefix and `minItems`, but not its `items`
- a default that isn't JSON is omitted

```ts
const T = type({
	big: "bigint",
	even: type("number").narrow(n => n % 2 === 0)
})

// was: throws
// now: { type: "object", properties: { big: {}, even: { type: "number" } }, ... }
T["~standard"].jsonSchema.input({ target: "draft-2020-12" })
```

Fallbacks from a scope's `toJsonSchema` config or from `libraryOptions` still take precedence, and `toJsonSchema()` itself still throws by default.

A `defaultValue` fallback can now return `undefined` to omit the default rather than writing `default: undefined`.
##### [v2.2.8](https://github.com/arktypeio/arktype/blob/HEAD/ark/type/CHANGELOG.md#228)

##### Add `string.base58`

Validates base58-encoded strings, which use the Bitcoin alphabet (no `0`, `O`, `I` or `l`):

```ts
const Base58 = type("string.base58")

// valid
Base58("3mJr7AoUXx2Wqd")
// ArkErrors: must be base58-encoded (was "0OIl")
Base58("0OIl")
```

Thanks to [@WolfieLeader](https://github.com/WolfieLeader).

##### Return empty `props` for `object`

`type("object").props` threw instead of returning the empty list of properties, like `type({}).props` does ([#1682](arktypeio/arktype#1682), fixes [#1177](arktypeio/arktype#1177)).

Thanks to [@SunilRathod27](https://github.com/SunilRathod27).

##### Keep object values from meta in JSON Schema

Meta values that aren't primitives, like an object or array `default` or a custom key like `x-unit`, were emitted as internal `$ark` references instead of their JSON values ([#1677](arktypeio/arktype#1677)). Defaults that aren't valid JSON, including functions, now go through the `defaultValue` fallback.

Thanks to [@lprnmns](https://github.com/lprnmns).

##### Report invalid generic definitions on TypeScript 7

TypeScript 7 only reports the error of the last overload that fails, which for an invalid generic definition was the tuple expression signature rather than ArkType's own message ([#1681](arktypeio/arktype#1681)):

```ts
// TypeScript 7 previously: Argument of type '"<n extends nummer>"' is not assignable to parameter of type '"Array" | ...
// now: 'nummer' is unresolvable
type("<n extends nummer>", "n > 0")
```

The generic and tuple expression signatures of `type` are now a single signature, so TypeScript 6 and 7 report the same errors directly, and errors in a generic's body point at the invalid property.
renovate Bot added a commit to cigaleapp/cigale that referenced this pull request Nov 2, 2026
##### [v2.2.9](https://github.com/arktypeio/arktype/blob/HEAD/ark/type/CHANGELOG.md#229)

##### Keep tuple elements around defaults in `.in` and `.out`

Combining a tuple's defaultable elements with its other elements dropped some of them, depending on key order:

```ts
const T = type(["string", "number = 5", "boolean?"])

// was: [string, boolean?]
// now: [string, number?, boolean?]
T.in.expression

// was: number[]
// now: [number, string, ...number[]]
type(["number", "string = 'foo'", "...", "number[]"]).out.expression
```

A bound that narrows two existing length constraints at once also no longer throws "multiple distinct intersection results":

```ts
// was: throws
// now: string == 2
type("1 <= string <= 2").and("string >= 2")
```

Thanks to [@ybai08](https://github.com/ybai08) ([#1696](arktypeio/arktype#1696)).

##### Reject `NaN` in unions discriminated by `typeof`

`number` rejects `NaN`, but compiled unions like `number | null` dropped that check when they discriminated by `typeof`, so `NaN` was only rejected with `jitless` ([#1702](arktypeio/arktype#1702)).

```ts
const T = type("number | null")

// was: NaN
// now: ArkErrors: must be a number (was NaN)
T(NaN)
```

Thanks to [@thecotne](https://github.com/thecotne).

##### Don't treat `Object.prototype` keys as declared

Inherited names like `toString` or `constructor`, and an own `__proto__` key like the one `JSON.parse` creates, were treated as declared keys, so `"+": "delete"` kept them and `"+": "reject"` accepted them ([#1701](arktypeio/arktype#1701)).

```ts
const T = type({ a: "string", "+": "reject" })

// was: { a: "x", constructor: 1 }
// now: ArkErrors: constructor must be removed
T({ a: "x", constructor: 1 })
```

Thanks to [@thecotne](https://github.com/thecotne).

##### Only emit referenced `$defs` in `toJsonSchema`

With `useRefs`, or for a cyclic type, every node a type referenced was written to `$defs`, including discriminated union cases that never appear in the output. Some of those couldn't be converted, so `toJsonSchema()` threw `Unexpected JSON Schema input for structure: {}` ([#1689](arktypeio/arktype#1689), fixes [#1612](arktypeio/arktype#1612), [#1511](arktypeio/arktype#1511) and [#1546](arktypeio/arktype#1546)).

```ts
const T = type.or(
	{ a: type.enumerated("a", "b", "c"), b: "1" },
	{ a: type.enumerated("a", "e", "f"), b: "2" }
)

// was: throws
// now: only the $defs that a $ref points to
T.toJsonSchema({ useRefs: true })
```

Thanks to [@giaBaoJS](https://github.com/giaBaoJS).

##### Convert unrepresentable types in `~standard.jsonSchema` instead of throwing

`~standard.jsonSchema.input` and `.output` now throw only for an unsupported `target`, i.e. one other than `draft-2020-12` or `draft-07`. Parts of a type that JSON Schema can't represent are converted instead ([#1694](arktypeio/arktype#1694)):

- a predicate, a second pattern, a `Date` bound or an array's non-index props is dropped from the schema it constrains
- `bigint`, `symbol`, a non-JSON unit like `undefined` and any prototype other than `Array` become `{}`
- a variadic tuple with postfix elements keeps its prefix and `minItems`, but not its `items`
- a default that isn't JSON is omitted

```ts
const T = type({
	big: "bigint",
	even: type("number").narrow(n => n % 2 === 0)
})

// was: throws
// now: { type: "object", properties: { big: {}, even: { type: "number" } }, ... }
T["~standard"].jsonSchema.input({ target: "draft-2020-12" })
```

Fallbacks from a scope's `toJsonSchema` config or from `libraryOptions` still take precedence, and `toJsonSchema()` itself still throws by default.

A `defaultValue` fallback can now return `undefined` to omit the default rather than writing `default: undefined`.
##### [v2.2.8](https://github.com/arktypeio/arktype/blob/HEAD/ark/type/CHANGELOG.md#228)

##### Add `string.base58`

Validates base58-encoded strings, which use the Bitcoin alphabet (no `0`, `O`, `I` or `l`):

```ts
const Base58 = type("string.base58")

// valid
Base58("3mJr7AoUXx2Wqd")
// ArkErrors: must be base58-encoded (was "0OIl")
Base58("0OIl")
```

Thanks to [@WolfieLeader](https://github.com/WolfieLeader).

##### Return empty `props` for `object`

`type("object").props` threw instead of returning the empty list of properties, like `type({}).props` does ([#1682](arktypeio/arktype#1682), fixes [#1177](arktypeio/arktype#1177)).

Thanks to [@SunilRathod27](https://github.com/SunilRathod27).

##### Keep object values from meta in JSON Schema

Meta values that aren't primitives, like an object or array `default` or a custom key like `x-unit`, were emitted as internal `$ark` references instead of their JSON values ([#1677](arktypeio/arktype#1677)). Defaults that aren't valid JSON, including functions, now go through the `defaultValue` fallback.

Thanks to [@lprnmns](https://github.com/lprnmns).

##### Report invalid generic definitions on TypeScript 7

TypeScript 7 only reports the error of the last overload that fails, which for an invalid generic definition was the tuple expression signature rather than ArkType's own message ([#1681](arktypeio/arktype#1681)):

```ts
// TypeScript 7 previously: Argument of type '"<n extends nummer>"' is not assignable to parameter of type '"Array" | ...
// now: 'nummer' is unresolvable
type("<n extends nummer>", "n > 0")
```

The generic and tuple expression signatures of `type` are now a single signature, so TypeScript 6 and 7 report the same errors directly, and errors in a generic's body point at the invalid property.
renovate Bot added a commit to cigaleapp/cigale that referenced this pull request Nov 8, 2026
##### [v2.2.9](https://github.com/arktypeio/arktype/blob/HEAD/ark/type/CHANGELOG.md#229)

##### Keep tuple elements around defaults in `.in` and `.out`

Combining a tuple's defaultable elements with its other elements dropped some of them, depending on key order:

```ts
const T = type(["string", "number = 5", "boolean?"])

// was: [string, boolean?]
// now: [string, number?, boolean?]
T.in.expression

// was: number[]
// now: [number, string, ...number[]]
type(["number", "string = 'foo'", "...", "number[]"]).out.expression
```

A bound that narrows two existing length constraints at once also no longer throws "multiple distinct intersection results":

```ts
// was: throws
// now: string == 2
type("1 <= string <= 2").and("string >= 2")
```

Thanks to [@ybai08](https://github.com/ybai08) ([#1696](arktypeio/arktype#1696)).

##### Reject `NaN` in unions discriminated by `typeof`

`number` rejects `NaN`, but compiled unions like `number | null` dropped that check when they discriminated by `typeof`, so `NaN` was only rejected with `jitless` ([#1702](arktypeio/arktype#1702)).

```ts
const T = type("number | null")

// was: NaN
// now: ArkErrors: must be a number (was NaN)
T(NaN)
```

Thanks to [@thecotne](https://github.com/thecotne).

##### Don't treat `Object.prototype` keys as declared

Inherited names like `toString` or `constructor`, and an own `__proto__` key like the one `JSON.parse` creates, were treated as declared keys, so `"+": "delete"` kept them and `"+": "reject"` accepted them ([#1701](arktypeio/arktype#1701)).

```ts
const T = type({ a: "string", "+": "reject" })

// was: { a: "x", constructor: 1 }
// now: ArkErrors: constructor must be removed
T({ a: "x", constructor: 1 })
```

Thanks to [@thecotne](https://github.com/thecotne).

##### Only emit referenced `$defs` in `toJsonSchema`

With `useRefs`, or for a cyclic type, every node a type referenced was written to `$defs`, including discriminated union cases that never appear in the output. Some of those couldn't be converted, so `toJsonSchema()` threw `Unexpected JSON Schema input for structure: {}` ([#1689](arktypeio/arktype#1689), fixes [#1612](arktypeio/arktype#1612), [#1511](arktypeio/arktype#1511) and [#1546](arktypeio/arktype#1546)).

```ts
const T = type.or(
	{ a: type.enumerated("a", "b", "c"), b: "1" },
	{ a: type.enumerated("a", "e", "f"), b: "2" }
)

// was: throws
// now: only the $defs that a $ref points to
T.toJsonSchema({ useRefs: true })
```

Thanks to [@giaBaoJS](https://github.com/giaBaoJS).

##### Convert unrepresentable types in `~standard.jsonSchema` instead of throwing

`~standard.jsonSchema.input` and `.output` now throw only for an unsupported `target`, i.e. one other than `draft-2020-12` or `draft-07`. Parts of a type that JSON Schema can't represent are converted instead ([#1694](arktypeio/arktype#1694)):

- a predicate, a second pattern, a `Date` bound or an array's non-index props is dropped from the schema it constrains
- `bigint`, `symbol`, a non-JSON unit like `undefined` and any prototype other than `Array` become `{}`
- a variadic tuple with postfix elements keeps its prefix and `minItems`, but not its `items`
- a default that isn't JSON is omitted

```ts
const T = type({
	big: "bigint",
	even: type("number").narrow(n => n % 2 === 0)
})

// was: throws
// now: { type: "object", properties: { big: {}, even: { type: "number" } }, ... }
T["~standard"].jsonSchema.input({ target: "draft-2020-12" })
```

Fallbacks from a scope's `toJsonSchema` config or from `libraryOptions` still take precedence, and `toJsonSchema()` itself still throws by default.

A `defaultValue` fallback can now return `undefined` to omit the default rather than writing `default: undefined`.
##### [v2.2.8](https://github.com/arktypeio/arktype/blob/HEAD/ark/type/CHANGELOG.md#228)

##### Add `string.base58`

Validates base58-encoded strings, which use the Bitcoin alphabet (no `0`, `O`, `I` or `l`):

```ts
const Base58 = type("string.base58")

// valid
Base58("3mJr7AoUXx2Wqd")
// ArkErrors: must be base58-encoded (was "0OIl")
Base58("0OIl")
```

Thanks to [@WolfieLeader](https://github.com/WolfieLeader).

##### Return empty `props` for `object`

`type("object").props` threw instead of returning the empty list of properties, like `type({}).props` does ([#1682](arktypeio/arktype#1682), fixes [#1177](arktypeio/arktype#1177)).

Thanks to [@SunilRathod27](https://github.com/SunilRathod27).

##### Keep object values from meta in JSON Schema

Meta values that aren't primitives, like an object or array `default` or a custom key like `x-unit`, were emitted as internal `$ark` references instead of their JSON values ([#1677](arktypeio/arktype#1677)). Defaults that aren't valid JSON, including functions, now go through the `defaultValue` fallback.

Thanks to [@lprnmns](https://github.com/lprnmns).

##### Report invalid generic definitions on TypeScript 7

TypeScript 7 only reports the error of the last overload that fails, which for an invalid generic definition was the tuple expression signature rather than ArkType's own message ([#1681](arktypeio/arktype#1681)):

```ts
// TypeScript 7 previously: Argument of type '"<n extends nummer>"' is not assignable to parameter of type '"Array" | ...
// now: 'nummer' is unresolvable
type("<n extends nummer>", "n > 0")
```

The generic and tuple expression signatures of `type` are now a single signature, so TypeScript 6 and 7 report the same errors directly, and errors in a generic's body point at the invalid property.
renovate Bot added a commit to cigaleapp/cigale that referenced this pull request Nov 9, 2026
##### [v2.2.9](https://github.com/arktypeio/arktype/blob/HEAD/ark/type/CHANGELOG.md#229)

##### Keep tuple elements around defaults in `.in` and `.out`

Combining a tuple's defaultable elements with its other elements dropped some of them, depending on key order:

```ts
const T = type(["string", "number = 5", "boolean?"])

// was: [string, boolean?]
// now: [string, number?, boolean?]
T.in.expression

// was: number[]
// now: [number, string, ...number[]]
type(["number", "string = 'foo'", "...", "number[]"]).out.expression
```

A bound that narrows two existing length constraints at once also no longer throws "multiple distinct intersection results":

```ts
// was: throws
// now: string == 2
type("1 <= string <= 2").and("string >= 2")
```

Thanks to [@ybai08](https://github.com/ybai08) ([#1696](arktypeio/arktype#1696)).

##### Reject `NaN` in unions discriminated by `typeof`

`number` rejects `NaN`, but compiled unions like `number | null` dropped that check when they discriminated by `typeof`, so `NaN` was only rejected with `jitless` ([#1702](arktypeio/arktype#1702)).

```ts
const T = type("number | null")

// was: NaN
// now: ArkErrors: must be a number (was NaN)
T(NaN)
```

Thanks to [@thecotne](https://github.com/thecotne).

##### Don't treat `Object.prototype` keys as declared

Inherited names like `toString` or `constructor`, and an own `__proto__` key like the one `JSON.parse` creates, were treated as declared keys, so `"+": "delete"` kept them and `"+": "reject"` accepted them ([#1701](arktypeio/arktype#1701)).

```ts
const T = type({ a: "string", "+": "reject" })

// was: { a: "x", constructor: 1 }
// now: ArkErrors: constructor must be removed
T({ a: "x", constructor: 1 })
```

Thanks to [@thecotne](https://github.com/thecotne).

##### Only emit referenced `$defs` in `toJsonSchema`

With `useRefs`, or for a cyclic type, every node a type referenced was written to `$defs`, including discriminated union cases that never appear in the output. Some of those couldn't be converted, so `toJsonSchema()` threw `Unexpected JSON Schema input for structure: {}` ([#1689](arktypeio/arktype#1689), fixes [#1612](arktypeio/arktype#1612), [#1511](arktypeio/arktype#1511) and [#1546](arktypeio/arktype#1546)).

```ts
const T = type.or(
	{ a: type.enumerated("a", "b", "c"), b: "1" },
	{ a: type.enumerated("a", "e", "f"), b: "2" }
)

// was: throws
// now: only the $defs that a $ref points to
T.toJsonSchema({ useRefs: true })
```

Thanks to [@giaBaoJS](https://github.com/giaBaoJS).

##### Convert unrepresentable types in `~standard.jsonSchema` instead of throwing

`~standard.jsonSchema.input` and `.output` now throw only for an unsupported `target`, i.e. one other than `draft-2020-12` or `draft-07`. Parts of a type that JSON Schema can't represent are converted instead ([#1694](arktypeio/arktype#1694)):

- a predicate, a second pattern, a `Date` bound or an array's non-index props is dropped from the schema it constrains
- `bigint`, `symbol`, a non-JSON unit like `undefined` and any prototype other than `Array` become `{}`
- a variadic tuple with postfix elements keeps its prefix and `minItems`, but not its `items`
- a default that isn't JSON is omitted

```ts
const T = type({
	big: "bigint",
	even: type("number").narrow(n => n % 2 === 0)
})

// was: throws
// now: { type: "object", properties: { big: {}, even: { type: "number" } }, ... }
T["~standard"].jsonSchema.input({ target: "draft-2020-12" })
```

Fallbacks from a scope's `toJsonSchema` config or from `libraryOptions` still take precedence, and `toJsonSchema()` itself still throws by default.

A `defaultValue` fallback can now return `undefined` to omit the default rather than writing `default: undefined`.
##### [v2.2.8](https://github.com/arktypeio/arktype/blob/HEAD/ark/type/CHANGELOG.md#228)

##### Add `string.base58`

Validates base58-encoded strings, which use the Bitcoin alphabet (no `0`, `O`, `I` or `l`):

```ts
const Base58 = type("string.base58")

// valid
Base58("3mJr7AoUXx2Wqd")
// ArkErrors: must be base58-encoded (was "0OIl")
Base58("0OIl")
```

Thanks to [@WolfieLeader](https://github.com/WolfieLeader).

##### Return empty `props` for `object`

`type("object").props` threw instead of returning the empty list of properties, like `type({}).props` does ([#1682](arktypeio/arktype#1682), fixes [#1177](arktypeio/arktype#1177)).

Thanks to [@SunilRathod27](https://github.com/SunilRathod27).

##### Keep object values from meta in JSON Schema

Meta values that aren't primitives, like an object or array `default` or a custom key like `x-unit`, were emitted as internal `$ark` references instead of their JSON values ([#1677](arktypeio/arktype#1677)). Defaults that aren't valid JSON, including functions, now go through the `defaultValue` fallback.

Thanks to [@lprnmns](https://github.com/lprnmns).

##### Report invalid generic definitions on TypeScript 7

TypeScript 7 only reports the error of the last overload that fails, which for an invalid generic definition was the tuple expression signature rather than ArkType's own message ([#1681](arktypeio/arktype#1681)):

```ts
// TypeScript 7 previously: Argument of type '"<n extends nummer>"' is not assignable to parameter of type '"Array" | ...
// now: 'nummer' is unresolvable
type("<n extends nummer>", "n > 0")
```

The generic and tuple expression signatures of `type` are now a single signature, so TypeScript 6 and 7 report the same errors directly, and errors in a generic's body point at the invalid property.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done (merged or closed)

Development

Successfully merging this pull request may close these issues.

1 participant