Skip to content

Commit 4c7e818

Browse files
committed
Less elaboration, non-strict-mode fix
1 parent 57f17bb commit 4c7e818

File tree

51 files changed

+42
-258
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+42
-258
lines changed

src/compiler/checker.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -19564,20 +19564,20 @@ namespace ts {
1956419564
// IndexedAccess comparisons are handled above in the `targetFlags & TypeFlage.IndexedAccess` branch
1956519565
if (!(sourceFlags & TypeFlags.IndexedAccess && targetFlags & TypeFlags.IndexedAccess)) {
1956619566
const constraint = getConstraintOfType(source as TypeVariable) || unknownType;
19567-
if (!strictNullChecks && (!constraint || (sourceFlags & TypeFlags.TypeParameter && constraint.flags & TypeFlags.Any))) {
19567+
if (!strictNullChecks && (!getConstraintOfType(source as TypeVariable) || (sourceFlags & TypeFlags.TypeParameter && constraint.flags & TypeFlags.Any))) {
1956819568
// A type variable with no constraint is not related to the non-primitive object type.
1956919569
if (result = isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~TypeFlags.NonPrimitive), RecursionFlags.Both)) {
1957019570
resetErrorInfo(saveErrorInfo);
1957119571
return result;
1957219572
}
1957319573
}
1957419574
// hi-speed no-this-instantiation check (less accurate, but avoids costly `this`-instantiation when the constraint will suffice), see #28231 for report on why this is needed
19575-
else if (result = isRelatedTo(constraint, target, RecursionFlags.Source, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
19575+
if (result = isRelatedTo(constraint, target, RecursionFlags.Source, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
1957619576
resetErrorInfo(saveErrorInfo);
1957719577
return result;
1957819578
}
1957919579
// slower, fuller, this-instantiated check (necessary when comparing raw `this` types from base classes), see `subclassWithPolymorphicThisIsAssignable.ts` test for example
19580-
else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, RecursionFlags.Source, reportErrors && !(targetFlags & sourceFlags & TypeFlags.TypeParameter), /*headMessage*/ undefined, intersectionState)) {
19580+
else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, RecursionFlags.Source, reportErrors && constraint !== unknownType && !(targetFlags & sourceFlags & TypeFlags.TypeParameter), /*headMessage*/ undefined, intersectionState)) {
1958119581
resetErrorInfo(saveErrorInfo);
1958219582
return result;
1958319583
}

tests/baselines/reference/assignmentCompatWithCallSignatures3.errors.txt

-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(47,1): error TS2322: Type '(x: number) => number[]' is not assignable to type '<T>(x: T) => T[]'.
22
Types of parameters 'x' and 'x' are incompatible.
33
Type 'T' is not assignable to type 'number'.
4-
Type 'unknown' is not assignable to type 'number'.
54
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(50,1): error TS2322: Type '(x: number) => string[]' is not assignable to type '<T>(x: T) => string[]'.
65
Types of parameters 'x' and 'x' are incompatible.
76
Type 'T' is not assignable to type 'number'.
8-
Type 'unknown' is not assignable to type 'number'.
97
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(53,1): error TS2322: Type '(x: number) => void' is not assignable to type '<T>(x: T) => T'.
108
Types of parameters 'x' and 'x' are incompatible.
119
Type 'T' is not assignable to type 'number'.
12-
Type 'unknown' is not assignable to type 'number'.
1310
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(56,1): error TS2322: Type '(x: string, y: number) => string' is not assignable to type '<T, U>(x: T, y: U) => T'.
1411
Types of parameters 'x' and 'x' are incompatible.
1512
Type 'T' is not assignable to type 'string'.
16-
Type 'unknown' is not assignable to type 'string'.
1713
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(59,1): error TS2322: Type '(x: (arg: string) => number) => string' is not assignable to type '<T, U>(x: (arg: T) => U) => T'.
1814
Types of parameters 'x' and 'x' are incompatible.
1915
Types of parameters 'arg' and 'arg' are incompatible.
@@ -64,7 +60,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
6460
Type '{ a: T; b: T; }' is not assignable to type '{ a: string; b: number; }'.
6561
Types of property 'a' are incompatible.
6662
Type 'T' is not assignable to type 'string'.
67-
Type 'unknown' is not assignable to type 'string'.
6863

6964

7065
==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts (15 errors) ====
@@ -119,31 +114,27 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
119114
!!! error TS2322: Type '(x: number) => number[]' is not assignable to type '<T>(x: T) => T[]'.
120115
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
121116
!!! error TS2322: Type 'T' is not assignable to type 'number'.
122-
!!! error TS2322: Type 'unknown' is not assignable to type 'number'.
123117
var b2: <T>(x: T) => string[];
124118
a2 = b2; // ok
125119
b2 = a2; // ok
126120
~~
127121
!!! error TS2322: Type '(x: number) => string[]' is not assignable to type '<T>(x: T) => string[]'.
128122
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
129123
!!! error TS2322: Type 'T' is not assignable to type 'number'.
130-
!!! error TS2322: Type 'unknown' is not assignable to type 'number'.
131124
var b3: <T>(x: T) => T;
132125
a3 = b3; // ok
133126
b3 = a3; // ok
134127
~~
135128
!!! error TS2322: Type '(x: number) => void' is not assignable to type '<T>(x: T) => T'.
136129
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
137130
!!! error TS2322: Type 'T' is not assignable to type 'number'.
138-
!!! error TS2322: Type 'unknown' is not assignable to type 'number'.
139131
var b4: <T, U>(x: T, y: U) => T;
140132
a4 = b4; // ok
141133
b4 = a4; // ok
142134
~~
143135
!!! error TS2322: Type '(x: string, y: number) => string' is not assignable to type '<T, U>(x: T, y: U) => T'.
144136
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
145137
!!! error TS2322: Type 'T' is not assignable to type 'string'.
146-
!!! error TS2322: Type 'unknown' is not assignable to type 'string'.
147138
var b5: <T, U>(x: (arg: T) => U) => T;
148139
a5 = b5; // ok
149140
b5 = a5; // ok
@@ -236,7 +227,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
236227
!!! error TS2322: Type '{ a: T; b: T; }' is not assignable to type '{ a: string; b: number; }'.
237228
!!! error TS2322: Types of property 'a' are incompatible.
238229
!!! error TS2322: Type 'T' is not assignable to type 'string'.
239-
!!! error TS2322: Type 'unknown' is not assignable to type 'string'.
240230
var b15: <T>(x: T) => T[];
241231
a15 = b15; // ok
242232
b15 = a15; // ok

tests/baselines/reference/assignmentCompatWithCallSignatures4.errors.txt

-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(45,9): error TS2322: Type '(x: number) => string[]' is not assignable to type '<T, U>(x: T) => U[]'.
22
Types of parameters 'x' and 'x' are incompatible.
33
Type 'T' is not assignable to type 'number'.
4-
Type 'unknown' is not assignable to type 'number'.
54
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(49,9): error TS2322: Type '(x: (arg: Base) => Derived) => (r: Base) => Derived2' is not assignable to type '<T extends Base, U extends Derived, V extends Derived2>(x: (arg: T) => U) => (r: T) => V'.
65
Types of parameters 'x' and 'x' are incompatible.
76
Types of parameters 'arg' and 'arg' are incompatible.
@@ -37,7 +36,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
3736
Type '{ a: T; b: T; }' is not assignable to type '{ a: string; b: number; }'.
3837
Types of property 'a' are incompatible.
3938
Type 'T' is not assignable to type 'string'.
40-
Type 'unknown' is not assignable to type 'string'.
4139
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(73,9): error TS2322: Type '<T extends Base>(x: { a: T; b: T; }) => number' is not assignable to type '(x: { a: string; b: number; }) => number'.
4240
Types of parameters 'x' and 'x' are incompatible.
4341
Type '{ a: string; b: number; }' is not assignable to type '{ a: Base; b: Base; }'.
@@ -56,11 +54,9 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
5654
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(90,9): error TS2322: Type '<T>(x: T) => T[]' is not assignable to type '<T>(x: T) => string[]'.
5755
Type 'T[]' is not assignable to type 'string[]'.
5856
Type 'T' is not assignable to type 'string'.
59-
Type 'unknown' is not assignable to type 'string'.
6057
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(95,9): error TS2322: Type '<T>(x: T) => T[]' is not assignable to type '<T>(x: T) => string[]'.
6158
Type 'T[]' is not assignable to type 'string[]'.
6259
Type 'T' is not assignable to type 'string'.
63-
Type 'unknown' is not assignable to type 'string'.
6460
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(96,9): error TS2322: Type '<T>(x: T) => string[]' is not assignable to type '<T>(x: T) => T[]'.
6561
Type 'string[]' is not assignable to type 'T[]'.
6662
Type 'string' is not assignable to type 'T'.
@@ -117,7 +113,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
117113
!!! error TS2322: Type '(x: number) => string[]' is not assignable to type '<T, U>(x: T) => U[]'.
118114
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
119115
!!! error TS2322: Type 'T' is not assignable to type 'number'.
120-
!!! error TS2322: Type 'unknown' is not assignable to type 'number'.
121116

122117
var b7: <T extends Base, U extends Derived, V extends Derived2>(x: (arg: T) => U) => (r: T) => V;
123118
a7 = b7;
@@ -186,7 +181,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
186181
!!! error TS2322: Type '{ a: T; b: T; }' is not assignable to type '{ a: string; b: number; }'.
187182
!!! error TS2322: Types of property 'a' are incompatible.
188183
!!! error TS2322: Type 'T' is not assignable to type 'string'.
189-
!!! error TS2322: Type 'unknown' is not assignable to type 'string'.
190184

191185
var b15a: <T extends Base>(x: { a: T; b: T }) => number;
192186
a15 = b15a;
@@ -229,7 +223,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
229223
!!! error TS2322: Type '<T>(x: T) => T[]' is not assignable to type '<T>(x: T) => string[]'.
230224
!!! error TS2322: Type 'T[]' is not assignable to type 'string[]'.
231225
!!! error TS2322: Type 'T' is not assignable to type 'string'.
232-
!!! error TS2322: Type 'unknown' is not assignable to type 'string'.
233226

234227
// target type has generic call signature
235228
var a3: <T>(x: T) => string[];
@@ -239,7 +232,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
239232
!!! error TS2322: Type '<T>(x: T) => T[]' is not assignable to type '<T>(x: T) => string[]'.
240233
!!! error TS2322: Type 'T[]' is not assignable to type 'string[]'.
241234
!!! error TS2322: Type 'T' is not assignable to type 'string'.
242-
!!! error TS2322: Type 'unknown' is not assignable to type 'string'.
243235
b3 = a3;
244236
~~
245237
!!! error TS2322: Type '<T>(x: T) => string[]' is not assignable to type '<T>(x: T) => T[]'.

tests/baselines/reference/assignmentCompatWithCallSignatures5.errors.txt

-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
1818
Type '{ a: U; b: V; }' is not assignable to type '{ a: Base; b: Base; }'.
1919
Types of property 'a' are incompatible.
2020
Type 'U' is not assignable to type 'Base'.
21-
Property 'foo' is missing in type '{}' but required in type 'Base'.
2221

2322

2423
==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures5.ts (4 errors) ====
@@ -104,8 +103,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
104103
!!! error TS2322: Type '{ a: U; b: V; }' is not assignable to type '{ a: Base; b: Base; }'.
105104
!!! error TS2322: Types of property 'a' are incompatible.
106105
!!! error TS2322: Type 'U' is not assignable to type 'Base'.
107-
!!! error TS2322: Property 'foo' is missing in type '{}' but required in type 'Base'.
108-
!!! related TS2728 tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures5.ts:3:14: 'foo' is declared here.
109106
var b17: <T>(x: (a: T) => T) => T[];
110107
a17 = b17; // ok
111108
b17 = a17; // ok

tests/baselines/reference/assignmentCompatWithCallSignatures6.errors.txt

+1-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
1212
Type '{ a: T; b: T; }' is not assignable to type '{ a: Base; b: Base; }'.
1313
Types of property 'a' are incompatible.
1414
Type 'T' is not assignable to type 'Base'.
15-
Property 'foo' is missing in type '{}' but required in type 'Base'.
1615

1716

1817
==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures6.ts (3 errors) ====
@@ -74,6 +73,4 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
7473
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
7574
!!! error TS2322: Type '{ a: T; b: T; }' is not assignable to type '{ a: Base; b: Base; }'.
7675
!!! error TS2322: Types of property 'a' are incompatible.
77-
!!! error TS2322: Type 'T' is not assignable to type 'Base'.
78-
!!! error TS2322: Property 'foo' is missing in type '{}' but required in type 'Base'.
79-
!!! related TS2728 tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures6.ts:3:14: 'foo' is declared here.
76+
!!! error TS2322: Type 'T' is not assignable to type 'Base'.

tests/baselines/reference/assignmentCompatWithConstructSignatures3.errors.txt

-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3.ts(47,1): error TS2322: Type 'new (x: number) => number[]' is not assignable to type 'new <T>(x: T) => T[]'.
22
Types of parameters 'x' and 'x' are incompatible.
33
Type 'T' is not assignable to type 'number'.
4-
Type 'unknown' is not assignable to type 'number'.
54
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3.ts(50,1): error TS2322: Type 'new (x: number) => string[]' is not assignable to type 'new <T>(x: T) => string[]'.
65
Types of parameters 'x' and 'x' are incompatible.
76
Type 'T' is not assignable to type 'number'.
8-
Type 'unknown' is not assignable to type 'number'.
97
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3.ts(53,1): error TS2322: Type 'new (x: number) => void' is not assignable to type 'new <T>(x: T) => T'.
108
Types of parameters 'x' and 'x' are incompatible.
119
Type 'T' is not assignable to type 'number'.
12-
Type 'unknown' is not assignable to type 'number'.
1310
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3.ts(56,1): error TS2322: Type 'new (x: string, y: number) => string' is not assignable to type 'new <T, U>(x: T, y: U) => T'.
1411
Types of parameters 'x' and 'x' are incompatible.
1512
Type 'T' is not assignable to type 'string'.
16-
Type 'unknown' is not assignable to type 'string'.
1713
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3.ts(59,1): error TS2322: Type 'new (x: (arg: string) => number) => string' is not assignable to type 'new <T, U>(x: (arg: T) => U) => T'.
1814
Types of parameters 'x' and 'x' are incompatible.
1915
Types of parameters 'arg' and 'arg' are incompatible.
@@ -64,7 +60,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
6460
Type '{ a: T; b: T; }' is not assignable to type '{ a: string; b: number; }'.
6561
Types of property 'a' are incompatible.
6662
Type 'T' is not assignable to type 'string'.
67-
Type 'unknown' is not assignable to type 'string'.
6863

6964

7065
==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3.ts (15 errors) ====
@@ -119,31 +114,27 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
119114
!!! error TS2322: Type 'new (x: number) => number[]' is not assignable to type 'new <T>(x: T) => T[]'.
120115
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
121116
!!! error TS2322: Type 'T' is not assignable to type 'number'.
122-
!!! error TS2322: Type 'unknown' is not assignable to type 'number'.
123117
var b2: new <T>(x: T) => string[];
124118
a2 = b2; // ok
125119
b2 = a2; // ok
126120
~~
127121
!!! error TS2322: Type 'new (x: number) => string[]' is not assignable to type 'new <T>(x: T) => string[]'.
128122
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
129123
!!! error TS2322: Type 'T' is not assignable to type 'number'.
130-
!!! error TS2322: Type 'unknown' is not assignable to type 'number'.
131124
var b3: new <T>(x: T) => T;
132125
a3 = b3; // ok
133126
b3 = a3; // ok
134127
~~
135128
!!! error TS2322: Type 'new (x: number) => void' is not assignable to type 'new <T>(x: T) => T'.
136129
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
137130
!!! error TS2322: Type 'T' is not assignable to type 'number'.
138-
!!! error TS2322: Type 'unknown' is not assignable to type 'number'.
139131
var b4: new <T, U>(x: T, y: U) => T;
140132
a4 = b4; // ok
141133
b4 = a4; // ok
142134
~~
143135
!!! error TS2322: Type 'new (x: string, y: number) => string' is not assignable to type 'new <T, U>(x: T, y: U) => T'.
144136
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
145137
!!! error TS2322: Type 'T' is not assignable to type 'string'.
146-
!!! error TS2322: Type 'unknown' is not assignable to type 'string'.
147138
var b5: new <T, U>(x: (arg: T) => U) => T;
148139
a5 = b5; // ok
149140
b5 = a5; // ok
@@ -236,7 +227,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
236227
!!! error TS2322: Type '{ a: T; b: T; }' is not assignable to type '{ a: string; b: number; }'.
237228
!!! error TS2322: Types of property 'a' are incompatible.
238229
!!! error TS2322: Type 'T' is not assignable to type 'string'.
239-
!!! error TS2322: Type 'unknown' is not assignable to type 'string'.
240230
var b15: new <T>(x: T) => T[];
241231
a15 = b15; // ok
242232
b15 = a15; // ok

0 commit comments

Comments
 (0)