Skip to content

Commit e52b5cb

Browse files
committed
Change sentinels to unknown
1 parent 038d951 commit e52b5cb

File tree

78 files changed

+66
-539
lines changed

Some content is hidden

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

78 files changed

+66
-539
lines changed

Diff for: src/compiler/checker.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -692,9 +692,9 @@ namespace ts {
692692
// in getPropagatingFlagsOfTypes, and it is checked in inferFromTypes.
693693
anyFunctionType.objectFlags |= ObjectFlags.NonInferrableType;
694694

695-
const noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
696-
const circularConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
697-
const resolvingDefaultType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
695+
const noConstraintType = createIntrinsicType(TypeFlags.Unknown, "unknown");
696+
const circularConstraintType = createIntrinsicType(TypeFlags.Unknown, "unknown");
697+
const resolvingDefaultType = createIntrinsicType(TypeFlags.Unknown, "unknown");
698698

699699
const markerSuperType = createTypeParameter();
700700
const markerSubType = createTypeParameter();
@@ -12735,12 +12735,13 @@ namespace ts {
1273512735
function reportRelationError(message: DiagnosticMessage | undefined, source: Type, target: Type) {
1273612736
const [sourceType, targetType] = getTypeNamesForErrorDisplay(source, target);
1273712737

12738-
if (target.flags & TypeFlags.TypeParameter && target.immediateBaseConstraint !== undefined && isTypeAssignableTo(source, target.immediateBaseConstraint)) {
12738+
let constraint: Type | undefined;
12739+
if (target.flags & TypeFlags.TypeParameter && (constraint = getBaseConstraintOfType(target)) && isTypeAssignableTo(source, constraint)) {
1273912740
reportError(
1274012741
Diagnostics._0_is_assignable_to_the_constraint_of_type_1_but_1_could_be_instantiated_with_a_different_subtype_of_constraint_2,
1274112742
sourceType,
1274212743
targetType,
12743-
typeToString(target.immediateBaseConstraint),
12744+
typeToString(constraint),
1274412745
);
1274512746
}
1274612747

Diff for: tests/baselines/reference/assignmentCompatWithCallSignatures3.errors.txt

-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
1414
Types of parameters 'x' and 'x' are incompatible.
1515
Types of parameters 'arg' and 'arg' are incompatible.
1616
Type 'string' is not assignable to type 'T'.
17-
'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
1817
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(62,1): error TS2322: Type '(x: (arg: Base) => Derived) => Base' is not assignable to type '<T extends Base, U extends Derived>(x: (arg: T) => U) => T'.
1918
Types of parameters 'x' and 'x' are incompatible.
2019
Types of parameters 'arg' and 'arg' are incompatible.
@@ -143,7 +142,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
143142
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
144143
!!! error TS2322: Types of parameters 'arg' and 'arg' are incompatible.
145144
!!! error TS2322: Type 'string' is not assignable to type 'T'.
146-
!!! error TS2322: 'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
147145
var b6: <T extends Base, U extends Derived>(x: (arg: T) => U) => T;
148146
a6 = b6; // ok
149147
b6 = a6; // ok

Diff for: tests/baselines/reference/assignmentCompatWithCallSignatures4.errors.txt

-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
4747
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(89,9): error TS2322: Type '<T>(x: T) => string[]' is not assignable to type '<T>(x: T) => T[]'.
4848
Type 'string[]' is not assignable to type 'T[]'.
4949
Type 'string' is not assignable to type 'T'.
50-
'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
5150
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[]'.
5251
Type 'T[]' is not assignable to type 'string[]'.
5352
Type 'T' is not assignable to type 'string'.
@@ -57,7 +56,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
5756
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[]'.
5857
Type 'string[]' is not assignable to type 'T[]'.
5958
Type 'string' is not assignable to type 'T'.
60-
'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
6159

6260

6361
==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts (15 errors) ====
@@ -211,7 +209,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
211209
!!! error TS2322: Type '<T>(x: T) => string[]' is not assignable to type '<T>(x: T) => T[]'.
212210
!!! error TS2322: Type 'string[]' is not assignable to type 'T[]'.
213211
!!! error TS2322: Type 'string' is not assignable to type 'T'.
214-
!!! error TS2322: 'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
215212
b2 = a2;
216213
~~
217214
!!! error TS2322: Type '<T>(x: T) => T[]' is not assignable to type '<T>(x: T) => string[]'.
@@ -231,6 +228,5 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
231228
!!! error TS2322: Type '<T>(x: T) => string[]' is not assignable to type '<T>(x: T) => T[]'.
232229
!!! error TS2322: Type 'string[]' is not assignable to type 'T[]'.
233230
!!! error TS2322: Type 'string' is not assignable to type 'T'.
234-
!!! error TS2322: 'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
235231
}
236232
}

Diff for: tests/baselines/reference/assignmentCompatWithCallSignatures5.errors.txt

-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
55
Type '{ foo: U; bar: U; }' is not assignable to type '{ foo: T; bar: T; }'.
66
Types of property 'foo' are incompatible.
77
Type 'U' is not assignable to type 'T'.
8-
'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
98
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures5.ts(55,1): error TS2322: Type '<T>(x: { a: T; b: T; }) => T[]' is not assignable to type '<U, V>(x: { a: U; b: V; }) => U[]'.
109
Types of parameters 'x' and 'x' are incompatible.
1110
Type '{ a: U; b: V; }' is not assignable to type '{ a: U; b: U; }'.
1211
Types of property 'b' are incompatible.
1312
Type 'V' is not assignable to type 'U'.
14-
'V' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint '{}'.
1513
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures5.ts(58,1): error TS2322: Type '<T extends Base>(x: { a: T; b: T; }) => T[]' is not assignable to type '<U, V>(x: { a: U; b: V; }) => U[]'.
1614
Types of parameters 'x' and 'x' are incompatible.
1715
Type '{ a: U; b: V; }' is not assignable to type '{ a: Base; b: Base; }'.
@@ -81,7 +79,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
8179
!!! error TS2322: Type '{ foo: U; bar: U; }' is not assignable to type '{ foo: T; bar: T; }'.
8280
!!! error TS2322: Types of property 'foo' are incompatible.
8381
!!! error TS2322: Type 'U' is not assignable to type 'T'.
84-
!!! error TS2322: 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
8582
var b15: <U, V>(x: { a: U; b: V; }) => U[];
8683
a15 = b15; // ok, T = U, T = V
8784
b15 = a15; // ok
@@ -91,7 +88,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
9188
!!! error TS2322: Type '{ a: U; b: V; }' is not assignable to type '{ a: U; b: U; }'.
9289
!!! error TS2322: Types of property 'b' are incompatible.
9390
!!! error TS2322: Type 'V' is not assignable to type 'U'.
94-
!!! error TS2322: 'V' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint '{}'.
9591
var b16: <T>(x: { a: T; b: T }) => T[];
9692
a15 = b16; // ok
9793
b15 = a16; // ok

Diff for: tests/baselines/reference/assignmentCompatWithCallSignatures6.errors.txt

-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
55
Type '{ foo: U; bar: U; }' is not assignable to type '{ foo: T; bar: T; }'.
66
Types of property 'foo' are incompatible.
77
Type 'U' is not assignable to type 'T'.
8-
'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
98
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures6.ts(42,1): error TS2322: Type '<T extends Base>(x: { a: T; b: T; }) => T[]' is not assignable to type '<T>(x: { a: T; b: T; }) => T[]'.
109
Types of parameters 'x' and 'x' are incompatible.
1110
Type '{ a: T; b: T; }' is not assignable to type '{ a: Base; b: Base; }'.
@@ -62,7 +61,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
6261
!!! error TS2322: Type '{ foo: U; bar: U; }' is not assignable to type '{ foo: T; bar: T; }'.
6362
!!! error TS2322: Types of property 'foo' are incompatible.
6463
!!! error TS2322: Type 'U' is not assignable to type 'T'.
65-
!!! error TS2322: 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
6664
var b16: <T>(x: { a: T; b: T }) => T[];
6765
x.a16 = b16;
6866
b16 = x.a16;

Diff for: tests/baselines/reference/assignmentCompatWithConstructSignatures3.errors.txt

-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
1414
Types of parameters 'x' and 'x' are incompatible.
1515
Types of parameters 'arg' and 'arg' are incompatible.
1616
Type 'string' is not assignable to type 'T'.
17-
'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
1817
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3.ts(62,1): error TS2322: Type 'new (x: (arg: Base) => Derived) => Base' is not assignable to type 'new <T extends Base, U extends Derived>(x: (arg: T) => U) => T'.
1918
Types of parameters 'x' and 'x' are incompatible.
2019
Types of parameters 'arg' and 'arg' are incompatible.
@@ -143,7 +142,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
143142
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
144143
!!! error TS2322: Types of parameters 'arg' and 'arg' are incompatible.
145144
!!! error TS2322: Type 'string' is not assignable to type 'T'.
146-
!!! error TS2322: 'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
147145
var b6: new <T extends Base, U extends Derived>(x: (arg: T) => U) => T;
148146
a6 = b6; // ok
149147
b6 = a6; // ok

Diff for: tests/baselines/reference/assignmentCompatWithConstructSignatures4.errors.txt

-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
6363
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts(89,9): error TS2322: Type 'new <T>(x: T) => string[]' is not assignable to type 'new <T>(x: T) => T[]'.
6464
Type 'string[]' is not assignable to type 'T[]'.
6565
Type 'string' is not assignable to type 'T'.
66-
'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
6766
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts(90,9): error TS2322: Type 'new <T>(x: T) => T[]' is not assignable to type 'new <T>(x: T) => string[]'.
6867
Type 'T[]' is not assignable to type 'string[]'.
6968
Type 'T' is not assignable to type 'string'.
@@ -73,7 +72,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
7372
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts(96,9): error TS2322: Type 'new <T>(x: T) => string[]' is not assignable to type 'new <T>(x: T) => T[]'.
7473
Type 'string[]' is not assignable to type 'T[]'.
7574
Type 'string' is not assignable to type 'T'.
76-
'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
7775

7876

7977
==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts (19 errors) ====
@@ -247,7 +245,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
247245
!!! error TS2322: Type 'new <T>(x: T) => string[]' is not assignable to type 'new <T>(x: T) => T[]'.
248246
!!! error TS2322: Type 'string[]' is not assignable to type 'T[]'.
249247
!!! error TS2322: Type 'string' is not assignable to type 'T'.
250-
!!! error TS2322: 'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
251248
b2 = a2; // ok
252249
~~
253250
!!! error TS2322: Type 'new <T>(x: T) => T[]' is not assignable to type 'new <T>(x: T) => string[]'.
@@ -267,6 +264,5 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
267264
!!! error TS2322: Type 'new <T>(x: T) => string[]' is not assignable to type 'new <T>(x: T) => T[]'.
268265
!!! error TS2322: Type 'string[]' is not assignable to type 'T[]'.
269266
!!! error TS2322: Type 'string' is not assignable to type 'T'.
270-
!!! error TS2322: 'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
271267
}
272268
}

Diff for: tests/baselines/reference/assignmentCompatWithConstructSignatures5.errors.txt

-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
55
Type '{ foo: U; bar: U; }' is not assignable to type '{ foo: T; bar: T; }'.
66
Types of property 'foo' are incompatible.
77
Type 'U' is not assignable to type 'T'.
8-
'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
98
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures5.ts(55,1): error TS2322: Type 'new <T>(x: { a: T; b: T; }) => T[]' is not assignable to type 'new <U, V>(x: { a: U; b: V; }) => U[]'.
109
Types of parameters 'x' and 'x' are incompatible.
1110
Type '{ a: U; b: V; }' is not assignable to type '{ a: U; b: U; }'.
1211
Types of property 'b' are incompatible.
1312
Type 'V' is not assignable to type 'U'.
14-
'V' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint '{}'.
1513
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures5.ts(58,1): error TS2322: Type 'new <T extends Base>(x: { a: T; b: T; }) => T[]' is not assignable to type 'new <U, V>(x: { a: U; b: V; }) => U[]'.
1614
Types of parameters 'x' and 'x' are incompatible.
1715
Type '{ a: U; b: V; }' is not assignable to type '{ a: Base; b: Base; }'.
@@ -81,7 +79,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
8179
!!! error TS2322: Type '{ foo: U; bar: U; }' is not assignable to type '{ foo: T; bar: T; }'.
8280
!!! error TS2322: Types of property 'foo' are incompatible.
8381
!!! error TS2322: Type 'U' is not assignable to type 'T'.
84-
!!! error TS2322: 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
8582
var b15: new <U, V>(x: { a: U; b: V; }) => U[];
8683
a15 = b15; // ok
8784
b15 = a15; // ok
@@ -91,7 +88,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
9188
!!! error TS2322: Type '{ a: U; b: V; }' is not assignable to type '{ a: U; b: U; }'.
9289
!!! error TS2322: Types of property 'b' are incompatible.
9390
!!! error TS2322: Type 'V' is not assignable to type 'U'.
94-
!!! error TS2322: 'V' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint '{}'.
9591
var b16: new <T>(x: { a: T; b: T }) => T[];
9692
a15 = b16; // ok
9793
b15 = a16; // ok

Diff for: tests/baselines/reference/assignmentCompatWithConstructSignatures6.errors.txt

-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
55
Type '{ foo: U; bar: U; }' is not assignable to type '{ foo: T; bar: T; }'.
66
Types of property 'foo' are incompatible.
77
Type 'U' is not assignable to type 'T'.
8-
'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
98
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures6.ts(42,1): error TS2322: Type 'new <T extends Base>(x: { a: T; b: T; }) => T[]' is not assignable to type 'new <T>(x: { a: T; b: T; }) => T[]'.
109
Types of parameters 'x' and 'x' are incompatible.
1110
Type '{ a: T; b: T; }' is not assignable to type '{ a: Base; b: Base; }'.
@@ -62,7 +61,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
6261
!!! error TS2322: Type '{ foo: U; bar: U; }' is not assignable to type '{ foo: T; bar: T; }'.
6362
!!! error TS2322: Types of property 'foo' are incompatible.
6463
!!! error TS2322: Type 'U' is not assignable to type 'T'.
65-
!!! error TS2322: 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
6664
var b16: new <T>(x: { a: T; b: T }) => T[];
6765
x.a16 = b16;
6866
b16 = x.a16;

Diff for: tests/baselines/reference/assignmentCompatWithGenericCallSignatures2.errors.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignatures2.ts(15,1): error TS2322: Type 'B' is not assignable to type 'A'.
22
Types of parameters 'y' and 'y' are incompatible.
33
Type 'T[]' is not assignable to type 'T'.
4-
'T[]' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
54
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignatures2.ts(16,1): error TS2322: Type 'A' is not assignable to type 'B'.
65
Types of parameters 'y' and 'y' are incompatible.
76
Type 'S' is not assignable to type 'S[]'.
@@ -27,7 +26,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
2726
!!! error TS2322: Type 'B' is not assignable to type 'A'.
2827
!!! error TS2322: Types of parameters 'y' and 'y' are incompatible.
2928
!!! error TS2322: Type 'T[]' is not assignable to type 'T'.
30-
!!! error TS2322: 'T[]' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
3129
b = a;
3230
~
3331
!!! error TS2322: Type 'A' is not assignable to type 'B'.

0 commit comments

Comments
 (0)