Skip to content

Commit 3e45322

Browse files
committed
Optimize MaxItems Inference
1 parent d54f756 commit 3e45322

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/schema/static/_elements.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ type XWithMaxItemsRemap<Elements extends unknown[], MaxItems extends number, Res
5454
: Result
5555
)
5656
type XWithMaxItems<Schema extends XSchema, Elements extends unknown[],
57-
MaxItems extends number | null = Schema extends XMaxItems<infer MaxItems extends number> ? MaxItems : null,
58-
Result extends unknown[] = MaxItems extends number ? XWithMaxItemsRemap<Elements, MaxItems> : Elements
57+
Result extends unknown[] = Schema extends XMaxItems<infer MaxItems extends number>
58+
? XWithMaxItemsRemap<Elements, MaxItems>
59+
: Elements
5960
> = Result
6061
// ------------------------------------------------------------------
6162
// 3. XNeedsAdditionalItems - Does MaxItems constrain all Elements?

src/schema/static/required.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import type { XProperties } from '../types/properties.ts'
3636
// XStaticRequired
3737
// ------------------------------------------------------------------
3838
export type XStaticRequired<Stack extends string[], Root extends XSchema, Schema extends XSchema, Keys extends string[],
39-
// note: We only produce an property set if 'required' is present without 'properties'
39+
// Note: We only produce a property set if the Required keyword is isolated without Properties. This is because the
40+
// Properties inference will handle Required in full, but where an isolated Required implies that the defined keys
41+
// are required but should accept anything (unknown).
4042
Result extends Record<PropertyKey, unknown> = Schema extends XProperties ? {} : Record<Keys[number], unknown>
4143
> = Result

0 commit comments

Comments
 (0)