improve typings for TS with array and minItems maxItems#2272
Merged
Conversation
Member
|
There are some build errors. |
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 ? |
Contributor
Author
|
Hello @dvdsgl, How to try test-complete ? |
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello,
I add minItems and maxItems
With this add quicktype can improve typing for some use case