Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion tsc/internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -22192,7 +22192,7 @@ func (c *Checker) getReducedType(t *Type) *Type {
case t.flags&TypeFlagsIntersection != 0:
if t.objectFlags&ObjectFlagsIsNeverIntersectionComputed == 0 {
t.objectFlags |= ObjectFlagsIsNeverIntersectionComputed
if c.somePropertyReducesToNever(t) {
if !c.isMappingOfSameObjectType(t.Types()) && c.somePropertyReducesToNever(t) {
t.objectFlags |= ObjectFlagsIsNeverIntersection
}
}
Expand All @@ -22203,6 +22203,20 @@ func (c *Checker) getReducedType(t *Type) *Type {
return t
}

func (c *Checker) isMappingOfSameObjectType(types []*Type) bool {
if len(types) != 0 && types[0].objectFlags&ObjectFlagsMapped != 0 {
if firstType := c.getModifiersTypeFromMappedType(types[0]); firstType.flags&TypeFlagsObject != 0 {
for _, t := range types[1:] {
if t.objectFlags&ObjectFlagsMapped == 0 || c.getModifiersTypeFromMappedType(t) != firstType {
return false
}
}
return true
}
}
return false
}

func (c *Checker) somePropertyReducesToNever(t *Type) bool {
// Collect declaration counts for each property across all constituent types of the intersection.
counts := make(map[string]int)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ const Activity = z.object({
},
});
export type ActivityT = output<typeof Activity>;
>ActivityT : { name: string; subactivities: unknown; }
>ActivityT : { name: string; subactivities: any[] | null; }
>Activity : $ZodObject<{ name: $ZodString; readonly subactivities: $ZodNullable<$ZodArray<$ZodObject<any>>>; }>

// (4) reference through a separately-declared const
Expand Down Expand Up @@ -355,6 +355,6 @@ const NodeArray = z.array(Node1);
>Node1 : $ZodObject<{ name: $ZodString; readonly children: $ZodOptional<$ZodArray<$ZodObject<any>>>; }>

export type Node1T = output<typeof Node1>;
>Node1T : { name: string; children?: unknown; }
>Node1T : { name: string; children?: any[] | undefined; }
>Node1 : $ZodObject<{ name: $ZodString; readonly children: $ZodOptional<$ZodArray<$ZodObject<any>>>; }>

Loading
Loading