Commit 45971af
committed
Fix StaticUnion regression for non-tuple Array<TSchema>
In typebox 0.34, UnionStatic used a mapped-index-signature pattern
`{[K in keyof T]: Static<T[K]>}[number]` that resolved correctly for
both tuple types and general `TSchema[]` arrays.
In 1.x, StaticUnion was rewritten using head/tail destructuring with a
`Result = never` default. Because `TSchema[]` does not match
`[Left, ...Right]` (the array may be empty), `Static<TUnion<TSchema[]>>`
falls through to `never`. This regresses any code that builds a union
from a variable typed as a plain array:
const errors = [Type.Object(...), Type.Object(...)];
const schema = Type.Union(errors);
type T = Static<typeof schema>; // resolves to `never` instead of the union
Fix: add an `Array<infer Item extends TSchema>` fallback that infers the
element type when the input is not a tuple. Tuples still go through the
fast recursive path; the new branch only fires for general arrays.
Adds static tests covering:
- inline tuple inference (existing behaviour)
- generic TSchema[] (must not resolve to never)
- narrowed Array<TLiteral<1|2|3>> (must resolve to 1|2|3)1 parent ea23b86 commit 45971af
2 files changed
Lines changed: 41 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | | - | |
12 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
0 commit comments