You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support spread in recursive object inference #64531
interfaceSchema<O>{readonlyout: O}typeShape=Record<string,Schema<any>>;declarefunctionobject<SextendsShape>(shape: S): Schema<{[KinkeyofS]: S[K]["out"]}>;declarefunctionarray<TextendsSchema<any>>(el: T): Schema<T["out"][]>;declarefunctionstring(): Schema<string>;// works since #64311constA=object({name: string(),getchildren(){returnarray(A);},});// failsconstbase={name: string()};constB=object({
...base,getchildren(){returnarray(B);},});
🙁 Actual behavior
B is any, with TS7022 on B and TS7023 on children. A is the same declaration without the spread and infers Schema<{ name: string; readonly children: ...[] }>.
🙂 Expected behavior
B infers the same type as A.
Additional information about the issue
Spreading a shape is how Zod's docs extend an object schema, so right now a schema can't be both extended and recursive:
changed the title [-]Recursive object literal with a spread still infers any after #64311[/-][+]Support spread in recursive object inference[/+]on Sep 29, 2026
Activity
[-]Recursive object literal with a spread still infers any after #64311[/-][+]Support spread in recursive object inference[/+]