Skip to content

Commit 01f77f7

Browse files
Merge pull request microsoft#28695 from weswigham/overlappy-count-unit-only
Count only unit types when counting overlapping keys
2 parents 3d8668c + e594407 commit 01f77f7

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11980,7 +11980,7 @@ namespace ts {
1198011980
// Some subset overlap if we have only string literals.
1198111981
// If we have a union of index types, it seems likely that we
1198211982
// needed to elaborate between two generic mapped types anyway.
11983-
const len = length((overlap as UnionType).types);
11983+
const len = length(filter((overlap as UnionType).types, isUnitType));
1198411984
if (len >= matchingCount) {
1198511985
bestMatch = target;
1198611986
matchingCount = len;

tests/baselines/reference/inferTypes1.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ tests/cases/conformance/types/conditional/inferTypes1.ts(75,43): error TS4081: E
1818
tests/cases/conformance/types/conditional/inferTypes1.ts(82,44): error TS2344: Type 'U' does not satisfy the constraint 'string'.
1919
Type 'number' is not assignable to type 'string'.
2020
tests/cases/conformance/types/conditional/inferTypes1.ts(144,40): error TS2322: Type 'T' is not assignable to type 'string | number | symbol'.
21-
Type 'T' is not assignable to type 'string'.
21+
Type 'T' is not assignable to type 'symbol'.
2222

2323

2424
==== tests/cases/conformance/types/conditional/inferTypes1.ts (16 errors) ====
@@ -202,7 +202,7 @@ tests/cases/conformance/types/conditional/inferTypes1.ts(144,40): error TS2322:
202202
type B<T> = string extends T ? { [P in T]: void; } : T; // Error
203203
~
204204
!!! error TS2322: Type 'T' is not assignable to type 'string | number | symbol'.
205-
!!! error TS2322: Type 'T' is not assignable to type 'string'.
205+
!!! error TS2322: Type 'T' is not assignable to type 'symbol'.
206206

207207
// Repro from #22302
208208

tests/baselines/reference/intersectionWithUnionConstraint.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
tests/cases/conformance/types/intersection/intersectionWithUnionConstraint.ts(7,9): error TS2322: Type 'T & U' is not assignable to type 'string | number'.
22
Type 'string | undefined' is not assignable to type 'string | number'.
33
Type 'undefined' is not assignable to type 'string | number'.
4-
Type 'T & U' is not assignable to type 'string'.
4+
Type 'T & U' is not assignable to type 'number'.
55
tests/cases/conformance/types/intersection/intersectionWithUnionConstraint.ts(8,9): error TS2322: Type 'T & U' is not assignable to type 'string | null'.
66
Type 'string | undefined' is not assignable to type 'string | null'.
77
Type 'undefined' is not assignable to type 'string | null'.
@@ -32,7 +32,7 @@ tests/cases/conformance/types/intersection/intersectionWithUnionConstraint.ts(12
3232
!!! error TS2322: Type 'T & U' is not assignable to type 'string | number'.
3333
!!! error TS2322: Type 'string | undefined' is not assignable to type 'string | number'.
3434
!!! error TS2322: Type 'undefined' is not assignable to type 'string | number'.
35-
!!! error TS2322: Type 'T & U' is not assignable to type 'string'.
35+
!!! error TS2322: Type 'T & U' is not assignable to type 'number'.
3636
let y2: string | null = x; // Error
3737
~~
3838
!!! error TS2322: Type 'T & U' is not assignable to type 'string | null'.

tests/baselines/reference/mappedTypeErrors.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(128,16): error TS2322:
3737
tests/cases/conformance/types/mapped/mappedTypeErrors.ts(129,25): error TS2322: Type 'string' is not assignable to type 'number | undefined'.
3838
tests/cases/conformance/types/mapped/mappedTypeErrors.ts(130,39): error TS2322: Type 'string' is not assignable to type 'number | undefined'.
3939
tests/cases/conformance/types/mapped/mappedTypeErrors.ts(136,16): error TS2322: Type 'T' is not assignable to type 'string | number | symbol'.
40-
Type 'T' is not assignable to type 'string'.
40+
Type 'T' is not assignable to type 'symbol'.
4141
tests/cases/conformance/types/mapped/mappedTypeErrors.ts(136,21): error TS2536: Type 'P' cannot be used to index type 'T'.
4242
tests/cases/conformance/types/mapped/mappedTypeErrors.ts(148,17): error TS2339: Property 'foo' does not exist on type 'Pick<T, K>'.
4343
tests/cases/conformance/types/mapped/mappedTypeErrors.ts(152,17): error TS2339: Property 'foo' does not exist on type 'Record<K, number>'.
@@ -249,7 +249,7 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(152,17): error TS2339:
249249
pt: {[P in T]?: T[P]}, // note: should be in keyof T
250250
~
251251
!!! error TS2322: Type 'T' is not assignable to type 'string | number | symbol'.
252-
!!! error TS2322: Type 'T' is not assignable to type 'string'.
252+
!!! error TS2322: Type 'T' is not assignable to type 'symbol'.
253253
~~~~
254254
!!! error TS2536: Type 'P' cannot be used to index type 'T'.
255255
};

tests/baselines/reference/mappedTypeErrors2.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ tests/cases/conformance/types/mapped/mappedTypeErrors2.ts(9,30): error TS2536: T
22
tests/cases/conformance/types/mapped/mappedTypeErrors2.ts(13,30): error TS2536: Type 'K' cannot be used to index type 'T3'.
33
tests/cases/conformance/types/mapped/mappedTypeErrors2.ts(15,38): error TS2536: Type 'S' cannot be used to index type '{ [key in AB[S]]: true; }'.
44
tests/cases/conformance/types/mapped/mappedTypeErrors2.ts(15,47): error TS2322: Type 'AB[S]' is not assignable to type 'string | number | symbol'.
5-
Type 'AB[S]' is not assignable to type 'string'.
5+
Type 'AB[S]' is not assignable to type 'symbol'.
66
tests/cases/conformance/types/mapped/mappedTypeErrors2.ts(15,47): error TS2536: Type 'S' cannot be used to index type 'AB'.
77
tests/cases/conformance/types/mapped/mappedTypeErrors2.ts(17,49): error TS2536: Type 'L' cannot be used to index type '{ [key in AB[S]]: true; }'.
88

@@ -31,7 +31,7 @@ tests/cases/conformance/types/mapped/mappedTypeErrors2.ts(17,49): error TS2536:
3131
!!! error TS2536: Type 'S' cannot be used to index type '{ [key in AB[S]]: true; }'.
3232
~~~~~
3333
!!! error TS2322: Type 'AB[S]' is not assignable to type 'string | number | symbol'.
34-
!!! error TS2322: Type 'AB[S]' is not assignable to type 'string'.
34+
!!! error TS2322: Type 'AB[S]' is not assignable to type 'symbol'.
3535
~~~~~
3636
!!! error TS2536: Type 'S' cannot be used to index type 'AB'.
3737

0 commit comments

Comments
 (0)