Skip to content

improve typings for TS with array and minItems maxItems#2272

Merged
schani merged 15 commits into
glideapps:masterfrom
tolbon:feat/min_max_array
Jul 20, 2026
Merged

improve typings for TS with array and minItems maxItems#2272
schani merged 15 commits into
glideapps:masterfrom
tolbon:feat/min_max_array

Conversation

@tolbon

@tolbon tolbon commented May 13, 2023

Copy link
Copy Markdown
Contributor

Hello,
I add minItems and maxItems

With this add quicktype can improve typing for some use case

@dvdsgl

dvdsgl commented May 16, 2023

Copy link
Copy Markdown
Member

There are some build errors.

@tolbon

tolbon commented May 18, 2023

Copy link
Copy Markdown
Contributor Author

Helo @dvdsgl some errors are not in code I write and are already here. I fix errors I write. Do i need fix all of this ?

@tolbon

tolbon commented May 24, 2023

Copy link
Copy Markdown
Contributor Author

Hello @dvdsgl, How to try test-complete ?

dvdsgl and others added 11 commits June 3, 2023 17:33
Resolves conflicts against master's biome reformat, ESM import suffixes,
and the prefixItems-aware makeArrayType.  makeArrayType keeps master's
body — including the singularizeTypeNames call the PR's rebase had
dropped — and now takes the produced forArray attributes, which it puts
on the array type it builds.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Its name duplicated "minMaxItems", so it could never coexist with the
real minItems/maxItems attribute, and its reader was never called.
Also biome-format the minItems producer.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The attribute now lives on the array type itself, so the renderers read
it from there instead of from the item type, where it would leak into
item-type identity and unification.

The minItems tuple shape ([T, T, ...T[]] for minItems 2) moves from the
shared TS/Flow base renderer into the TypeScript renderer: Flow (pinned
at flow-bin 0.66 in CI) has no tuple-rest syntax, so Flow keeps plain
array types.  TypeScript spells out up to 16 guaranteed elements and
ignores maxItems, which nothing in the generated code enforces.  Zod
emits both z.array(T).min(n) and .max(m).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
ArrayType.reconstitute goes through getUniqueArrayType when its item
type isn't reconstituted yet, and that path added the type's attributes
after creation — which asserts for identity attributes.  Arrays never
had identity attributes before minItems/maxItems; now the attributes are
passed at type-creation time, like the object-type path already does.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The schema covers arrays with only minItems, only maxItems, both,
neither, and union item types.  The expected-failure samples are gated
on a new "minmaxitems" feature, declared only by typescript-zod — the
one tested language whose generated code enforces the constraints at
runtime (z.array(...).min/.max).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The schema-typescript fixture is not in the CI matrix yet; running it
locally hits three schemas whose generated interfaces mix declared
properties with a typed-additionalProperties index signature (TS2411).
They fail identically with unmodified master, so skip them with a note.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
unionItems is an int|string union array; kotlinx renders unions as
sealed classes without serializer wiring, so decoding the bare JSON
literals fails at runtime (glideapps#2951) — same reason as the other union
schemas in this list.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@schani
schani merged commit 408d4ff into glideapps:master Jul 20, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants