Skip to content

Commit 40ac892

Browse files
committed
Type comparison when conditional type is target
1 parent 3b919e2 commit 40ac892

8 files changed

+557
-310
lines changed

src/compiler/checker.ts

+74-57
Large diffs are not rendered by default.

src/compiler/types.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -4712,7 +4712,9 @@ namespace ts {
47124712
/* @internal */
47134713
resolvedInferredTrueType?: Type; // The `trueType` instantiated with the `combinedMapper`, if present
47144714
/* @internal */
4715-
resolvedDefaultConstraint?: Type;
4715+
resolvedDefaultConstraintForReading?: Type;
4716+
/* @internal */
4717+
resolvedDefaultConstraintForWriting?: Type;
47164718
/* @internal */
47174719
mapper?: TypeMapper;
47184720
/* @internal */

tests/baselines/reference/circularlyConstrainedMappedTypeContainingConditionalNoInfiniteInstantiationDepth.errors.txt

+144-84
Large diffs are not rendered by default.

tests/baselines/reference/conditionalTypes1.errors.txt

+106-18
Large diffs are not rendered by default.

tests/baselines/reference/conditionalTypes2.errors.txt

+4-42
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,9 @@
11
tests/cases/conformance/types/conditional/conditionalTypes2.ts(15,5): error TS2322: Type 'Covariant<A>' is not assignable to type 'Covariant<B>'.
22
Type 'A' is not assignable to type 'B'.
33
'A' is assignable to the constraint of type 'B', but 'B' could be instantiated with a different subtype of constraint '{}'.
4-
tests/cases/conformance/types/conditional/conditionalTypes2.ts(19,5): error TS2322: Type 'Contravariant<B>' is not assignable to type 'Contravariant<A>'.
4+
tests/cases/conformance/types/conditional/conditionalTypes2.ts(25,5): error TS2322: Type 'Invariant<A>' is not assignable to type 'Invariant<B>'.
55
Type 'A' is not assignable to type 'B'.
66
'A' is assignable to the constraint of type 'B', but 'B' could be instantiated with a different subtype of constraint '{}'.
7-
tests/cases/conformance/types/conditional/conditionalTypes2.ts(24,5): error TS2322: Type 'Invariant<B>' is not assignable to type 'Invariant<A>'.
8-
Types of property 'foo' are incompatible.
9-
Type 'B extends string ? keyof B : B' is not assignable to type 'A extends string ? keyof A : A'.
10-
Type 'keyof B' is not assignable to type 'keyof A'.
11-
Type 'string | number | symbol' is not assignable to type 'keyof A'.
12-
Type 'string' is not assignable to type 'keyof A'.
13-
Type 'string' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'.
14-
Type 'keyof B' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'.
15-
Type 'string | number | symbol' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'.
16-
Type 'string' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'.
17-
Type 'keyof B' is not assignable to type '"valueOf"'.
18-
Type 'string | number | symbol' is not assignable to type '"valueOf"'.
19-
Type 'string' is not assignable to type '"valueOf"'.
20-
tests/cases/conformance/types/conditional/conditionalTypes2.ts(25,5): error TS2322: Type 'Invariant<A>' is not assignable to type 'Invariant<B>'.
21-
Types of property 'foo' are incompatible.
22-
Type 'A extends string ? keyof A : A' is not assignable to type 'B extends string ? keyof B : B'.
23-
Type 'A' is not assignable to type 'B'.
24-
'A' is assignable to the constraint of type 'B', but 'B' could be instantiated with a different subtype of constraint '{}'.
257
tests/cases/conformance/types/conditional/conditionalTypes2.ts(73,12): error TS2345: Argument of type 'Extract<Extract<T, Foo>, Bar>' is not assignable to parameter of type '{ foo: string; bat: string; }'.
268
Property 'bat' is missing in type 'Bar & Foo' but required in type '{ foo: string; bat: string; }'.
279
Type 'Extract<T, Bar>' is not assignable to type '{ foo: string; bat: string; }'.
@@ -33,7 +15,7 @@ tests/cases/conformance/types/conditional/conditionalTypes2.ts(75,12): error TS2
3315
Property 'bat' is missing in type 'Bar & Foo' but required in type '{ foo: string; bat: string; }'.
3416

3517

36-
==== tests/cases/conformance/types/conditional/conditionalTypes2.ts (7 errors) ====
18+
==== tests/cases/conformance/types/conditional/conditionalTypes2.ts (5 errors) ====
3719
interface Covariant<T> {
3820
foo: T extends string ? T : number;
3921
}
@@ -57,36 +39,16 @@ tests/cases/conformance/types/conditional/conditionalTypes2.ts(75,12): error TS2
5739

5840
function f2<A, B extends A>(a: Contravariant<A>, b: Contravariant<B>) {
5941
a = b; // Error
60-
~
61-
!!! error TS2322: Type 'Contravariant<B>' is not assignable to type 'Contravariant<A>'.
62-
!!! error TS2322: Type 'A' is not assignable to type 'B'.
63-
!!! error TS2322: 'A' is assignable to the constraint of type 'B', but 'B' could be instantiated with a different subtype of constraint '{}'.
6442
b = a;
6543
}
6644

6745
function f3<A, B extends A>(a: Invariant<A>, b: Invariant<B>) {
6846
a = b; // Error
69-
~
70-
!!! error TS2322: Type 'Invariant<B>' is not assignable to type 'Invariant<A>'.
71-
!!! error TS2322: Types of property 'foo' are incompatible.
72-
!!! error TS2322: Type 'B extends string ? keyof B : B' is not assignable to type 'A extends string ? keyof A : A'.
73-
!!! error TS2322: Type 'keyof B' is not assignable to type 'keyof A'.
74-
!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'keyof A'.
75-
!!! error TS2322: Type 'string' is not assignable to type 'keyof A'.
76-
!!! error TS2322: Type 'string' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'.
77-
!!! error TS2322: Type 'keyof B' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'.
78-
!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'.
79-
!!! error TS2322: Type 'string' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'.
80-
!!! error TS2322: Type 'keyof B' is not assignable to type '"valueOf"'.
81-
!!! error TS2322: Type 'string | number | symbol' is not assignable to type '"valueOf"'.
82-
!!! error TS2322: Type 'string' is not assignable to type '"valueOf"'.
8347
b = a; // Error
8448
~
8549
!!! error TS2322: Type 'Invariant<A>' is not assignable to type 'Invariant<B>'.
86-
!!! error TS2322: Types of property 'foo' are incompatible.
87-
!!! error TS2322: Type 'A extends string ? keyof A : A' is not assignable to type 'B extends string ? keyof B : B'.
88-
!!! error TS2322: Type 'A' is not assignable to type 'B'.
89-
!!! error TS2322: 'A' is assignable to the constraint of type 'B', but 'B' could be instantiated with a different subtype of constraint '{}'.
50+
!!! error TS2322: Type 'A' is not assignable to type 'B'.
51+
!!! error TS2322: 'A' is assignable to the constraint of type 'B', but 'B' could be instantiated with a different subtype of constraint '{}'.
9052
}
9153

9254
// Extract<T, Function> is a T that is known to be a Function

tests/baselines/reference/conditionalTypesExcessProperties.errors.txt

-24
This file was deleted.

0 commit comments

Comments
 (0)