You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make type guard function types invariant in the type guarded for.
- Fix one break in the compiler.
- Type guards like `isNetworked(): this is (Networked & this)` have been
obsolete in favor of `isNetworked(): this is Networked` ever since
narrowing was enhanced to take an intersection in a370908, and the
first form now causes a problem: a subclass fails to be a subtype of
its superclass because `this` appears in a non-covariant position. So
replace all occurrences of the first form with the second form in the
test suite.
Fixes#26981.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(45,56): error TS2677: A type predicate's type must be assignable to its parameter's type.
18
18
Type 'T[]' is not assignable to type 'string'.
19
-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(59,7): error TS2551: Property 'propB' does not exist on type 'A'. Did you mean 'propA'?
20
-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(64,7): error TS2551: Property 'propB' does not exist on type 'A'. Did you mean 'propA'?
21
-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(69,7): error TS2551: Property 'propB' does not exist on type 'A'. Did you mean 'propA'?
22
-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(74,46): error TS2345: Argument of type '(p1: any) => p1 is C' is not assignable to parameter of type '(p1: any) => p1 is B'.
23
-
Type predicate 'p1 is C' is not assignable to 'p1 is B'.
24
-
Property 'propB' is missing in type 'C' but required in type 'B'.
25
-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(78,1): error TS2322: Type '(p1: any, p2: any) => boolean' is not assignable to type '(p1: any, p2: any) => p1 is A'.
19
+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(60,7): error TS2551: Property 'propB' does not exist on type 'A'. Did you mean 'propA'?
20
+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(65,7): error TS2551: Property 'propB' does not exist on type 'A'. Did you mean 'propA'?
21
+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(70,7): error TS2551: Property 'propB' does not exist on type 'A'. Did you mean 'propA'?
22
+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(75,46): error TS2345: Argument of type '(p1: any) => p1 is C' is not assignable to parameter of type '(p1: any) => p1 is A'.
23
+
Type predicate 'p1 is C' is not assignable to 'p1 is A'.
24
+
Property 'propC' is missing in type 'A' but required in type 'C'.
25
+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(77,47): error TS2345: Argument of type '(p1: any) => p1 is A' is not assignable to parameter of type '(p1: any) => p1 is C'.
26
+
Type predicate 'p1 is A' is not assignable to 'p1 is C'.
27
+
Type 'A' is not assignable to type 'C'.
28
+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(81,1): error TS2322: Type '(p1: any, p2: any) => boolean' is not assignable to type '(p1: any, p2: any) => p1 is A'.
26
29
Signature '(p1: any, p2: any): boolean' must be a type predicate.
27
-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(84,1): error TS2322: Type '(p1: any, p2: any) => p2 is A' is not assignable to type '(p1: any, p2: any) => p1 is A'.
30
+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(87,1): error TS2322: Type '(p1: any, p2: any) => p2 is A' is not assignable to type '(p1: any, p2: any) => p1 is A'.
28
31
Type predicate 'p2 is A' is not assignable to 'p1 is A'.
29
32
Parameter 'p2' is not in the same position as parameter 'p1'.
30
-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(90,1): error TS2322: Type '(p1: any, p2: any, p3: any) => p1 is A' is not assignable to type '(p1: any, p2: any) => p1 is A'.
31
-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(95,9): error TS2304: Cannot find name 'b'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(103,25): error TS1228: A type predicate is only allowed in return type position for functions and methods.
43
-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(104,9): error TS2322: Type 'true' is not assignable to type 'D'.
44
-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(104,9): error TS2409: Return type of constructor signature must be assignable to the instance type of the class.
45
-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(106,20): error TS1228: A type predicate is only allowed in return type position for functions and methods.
33
+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(93,1): error TS2322: Type '(p1: any, p2: any, p3: any) => p1 is A' is not assignable to type '(p1: any, p2: any) => p1 is A'.
34
+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(98,9): error TS2304: Cannot find name 'b'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(106,25): error TS1228: A type predicate is only allowed in return type position for functions and methods.
46
+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(107,9): error TS2322: Type 'true' is not assignable to type 'D'.
47
+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(107,9): error TS2409: Return type of constructor signature must be assignable to the instance type of the class.
46
48
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(109,20): error TS1228: A type predicate is only allowed in return type position for functions and methods.
47
-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(110,9): error TS2408: Setters cannot return a value.
48
-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(115,18): error TS1228: A type predicate is only allowed in return type position for functions and methods.
49
-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(119,22): error TS2304: Cannot find name 'p1'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(120,1): error TS1128: Declaration or statement expected.
53
-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(123,20): error TS1229: A type predicate cannot reference a rest parameter.
54
-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(128,34): error TS1230: A type predicate cannot reference element 'p1' in a binding pattern.
55
-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(132,34): error TS1230: A type predicate cannot reference element 'p1' in a binding pattern.
56
-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(136,39): error TS1230: A type predicate cannot reference element 'p1' in a binding pattern.
57
-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(152,68): error TS2344: Type 'T | "d"' does not satisfy the constraint 'Keys'.
49
+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(112,20): error TS1228: A type predicate is only allowed in return type position for functions and methods.
50
+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(113,9): error TS2408: Setters cannot return a value.
51
+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(118,18): error TS1228: A type predicate is only allowed in return type position for functions and methods.
52
+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(122,22): error TS2304: Cannot find name 'p1'.
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(123,1): error TS1128: Declaration or statement expected.
56
+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(126,20): error TS1229: A type predicate cannot reference a rest parameter.
57
+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(131,34): error TS1230: A type predicate cannot reference element 'p1' in a binding pattern.
58
+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(135,34): error TS1230: A type predicate cannot reference element 'p1' in a binding pattern.
59
+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(139,39): error TS1230: A type predicate cannot reference element 'p1' in a binding pattern.
60
+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(155,68): error TS2344: Type 'T | "d"' does not satisfy the constraint 'Keys'.
58
61
Type '"d"' is not assignable to type 'Keys'.
59
-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(159,31): error TS2344: Type 'Bar' does not satisfy the constraint 'Foo'.
62
+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(162,31): error TS2344: Type 'Bar' does not satisfy the constraint 'Foo'.
60
63
Types of property ''a'' are incompatible.
61
64
Type 'number' is not assignable to type 'string'.
62
-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(162,31): error TS2344: Type 'Bar' does not satisfy the constraint 'Foo'.
63
-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(163,35): error TS2344: Type 'number' does not satisfy the constraint 'Foo'.
64
-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(164,51): error TS2344: Type 'Bar' does not satisfy the constraint 'Foo'.
65
-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(165,51): error TS2344: Type 'number' does not satisfy the constraint 'Foo'.
66
-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(166,45): error TS2677: A type predicate's type must be assignable to its parameter's type.
65
+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(165,31): error TS2344: Type 'Bar' does not satisfy the constraint 'Foo'.
66
+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(166,35): error TS2344: Type 'number' does not satisfy the constraint 'Foo'.
67
+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(167,51): error TS2344: Type 'Bar' does not satisfy the constraint 'Foo'.
68
+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(168,51): error TS2344: Type 'number' does not satisfy the constraint 'Foo'.
69
+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(169,45): error TS2677: A type predicate's type must be assignable to its parameter's type.
67
70
Type 'NeedsFoo<number>' is not assignable to type 'number'.
68
-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(166,54): error TS2344: Type 'number' does not satisfy the constraint 'Foo'.
71
+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(169,54): error TS2344: Type 'number' does not satisfy the constraint 'Foo'.
0 commit comments