Skip to content

Commit 43f8ae6

Browse files
authored
Only normalize intersections that include {} (#50535)
* Only normalize intersections that include {} * Accept new baselines
1 parent d293e72 commit 43f8ae6

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18493,7 +18493,7 @@ namespace ts {
1849318493
if (reduced !== type) {
1849418494
return reduced;
1849518495
}
18496-
if (type.flags & TypeFlags.Intersection) {
18496+
if (type.flags & TypeFlags.Intersection && some((type as IntersectionType).types, isEmptyAnonymousObjectType)) {
1849718497
const normalizedTypes = sameMap(type.types, t => getNormalizedType(t, writing));
1849818498
if (normalizedTypes !== type.types) {
1849918499
return getIntersectionType(normalizedTypes);

tests/baselines/reference/conditionalTypes2.errors.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ tests/cases/conformance/types/conditional/conditionalTypes2.ts(74,12): error TS2
3232
Property 'bat' is missing in type 'Foo & Bar' but required in type '{ foo: string; bat: string; }'.
3333
tests/cases/conformance/types/conditional/conditionalTypes2.ts(75,12): error TS2345: Argument of type 'Extract2<T, Foo, Bar>' is not assignable to parameter of type '{ foo: string; bat: string; }'.
3434
Type 'T extends Bar ? T : never' is not assignable to type '{ foo: string; bat: string; }'.
35-
Type 'Bar & Foo & T' is not assignable to type '{ foo: string; bat: string; }'.
35+
Property 'bat' is missing in type 'Bar & Foo' but required in type '{ foo: string; bat: string; }'.
3636

3737

3838
==== tests/cases/conformance/types/conditional/conditionalTypes2.ts (7 errors) ====
@@ -159,7 +159,8 @@ tests/cases/conformance/types/conditional/conditionalTypes2.ts(75,12): error TS2
159159
~
160160
!!! error TS2345: Argument of type 'Extract2<T, Foo, Bar>' is not assignable to parameter of type '{ foo: string; bat: string; }'.
161161
!!! error TS2345: Type 'T extends Bar ? T : never' is not assignable to type '{ foo: string; bat: string; }'.
162-
!!! error TS2345: Type 'Bar & Foo & T' is not assignable to type '{ foo: string; bat: string; }'.
162+
!!! error TS2345: Property 'bat' is missing in type 'Bar & Foo' but required in type '{ foo: string; bat: string; }'.
163+
!!! related TS2728 tests/cases/conformance/types/conditional/conditionalTypes2.ts:62:43: 'bat' is declared here.
163164
}
164165

165166
// Repros from #22860

0 commit comments

Comments
 (0)