diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9a443e6c4449d..4449e6f85356c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11098,7 +11098,10 @@ namespace ts { } } - const related = compareTypes(source.type, target.type, reportErrors); + let related = compareTypes(source.type, target.type, reportErrors); + if (related) { + related &= compareTypes(target.type, source.type, reportErrors); + } if (related === Ternary.False && reportErrors) { errorReporter!(Diagnostics.Type_predicate_0_is_not_assignable_to_1, typePredicateToString(source), typePredicateToString(target)); } diff --git a/src/services/documentHighlights.ts b/src/services/documentHighlights.ts index f0f3c165d7eab..dfcc61da44e4d 100644 --- a/src/services/documentHighlights.ts +++ b/src/services/documentHighlights.ts @@ -75,7 +75,7 @@ namespace ts.DocumentHighlights { case SyntaxKind.SetKeyword: return getFromAllDeclarations(isAccessor, [SyntaxKind.GetKeyword, SyntaxKind.SetKeyword]); case SyntaxKind.AwaitKeyword: - return useParent(node.parent, isAwaitExpression, getAsyncAndAwaitOccurrences); + return useParent(node.parent, isAwaitExpression, getAsyncAndAwaitOccurrences); case SyntaxKind.AsyncKeyword: return highlightSpans(getAsyncAndAwaitOccurrences(node)); case SyntaxKind.YieldKeyword: diff --git a/tests/baselines/reference/typeGuardFunctionErrors.errors.txt b/tests/baselines/reference/typeGuardFunctionErrors.errors.txt index 13374b71236ce..5337b125a3d2d 100644 --- a/tests/baselines/reference/typeGuardFunctionErrors.errors.txt +++ b/tests/baselines/reference/typeGuardFunctionErrors.errors.txt @@ -17,60 +17,63 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(41,56) Type 'number' is not assignable to type 'string'. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(45,56): error TS2677: A type predicate's type must be assignable to its parameter's type. Type 'T[]' is not assignable to type 'string'. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(59,7): error TS2551: Property 'propB' does not exist on type 'A'. Did you mean 'propA'? -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(64,7): error TS2551: Property 'propB' does not exist on type 'A'. Did you mean 'propA'? -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(69,7): error TS2551: Property 'propB' does not exist on type 'A'. Did you mean 'propA'? -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'. - Type predicate 'p1 is C' is not assignable to 'p1 is B'. - Type 'C' is not assignable to type 'B'. - Property 'propB' is missing in type 'C'. -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'. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(60,7): error TS2551: Property 'propB' does not exist on type 'A'. Did you mean 'propA'? +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(65,7): error TS2551: Property 'propB' does not exist on type 'A'. Did you mean 'propA'? +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(70,7): error TS2551: Property 'propB' does not exist on type 'A'. Did you mean 'propA'? +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'. + Type predicate 'p1 is C' is not assignable to 'p1 is A'. + Type 'A' is not assignable to type 'C'. + Property 'propC' is missing in type 'A'. +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'. + Type predicate 'p1 is A' is not assignable to 'p1 is C'. + Type 'A' is not assignable to type 'C'. +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'. Signature '(p1: any, p2: any): boolean' must be a type predicate. -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'. +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'. Type predicate 'p2 is A' is not assignable to 'p1 is A'. Parameter 'p2' is not in the same position as parameter 'p1'. -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'. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(95,9): error TS2304: Cannot find name 'b'. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(95,11): error TS1005: ',' expected. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(95,14): error TS1005: ',' expected. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(95,14): error TS2300: Duplicate identifier 'A'. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(96,16): error TS2304: Cannot find name 'b'. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(96,18): error TS1005: ',' expected. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(96,21): error TS1005: ',' expected. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(97,20): error TS2304: Cannot find name 'b'. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(97,22): error TS1144: '{' or ';' expected. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(97,25): error TS1005: ';' expected. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(97,27): error TS1005: ';' expected. -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. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(104,9): error TS2322: Type 'true' is not assignable to type 'D'. -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. -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. +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'. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(98,9): error TS2304: Cannot find name 'b'. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(98,11): error TS1005: ',' expected. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(98,14): error TS1005: ',' expected. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(98,14): error TS2300: Duplicate identifier 'A'. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(99,16): error TS2304: Cannot find name 'b'. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(99,18): error TS1005: ',' expected. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(99,21): error TS1005: ',' expected. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(100,20): error TS2304: Cannot find name 'b'. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(100,22): error TS1144: '{' or ';' expected. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(100,25): error TS1005: ';' expected. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(100,27): error TS1005: ';' expected. +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. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(107,9): error TS2322: Type 'true' is not assignable to type 'D'. +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. 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. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(110,9): error TS2408: Setters cannot return a value. -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. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(119,22): error TS2304: Cannot find name 'p1'. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(119,25): error TS1005: ';' expected. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(119,28): error TS1005: ';' expected. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(120,1): error TS1128: Declaration or statement expected. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(123,20): error TS1229: A type predicate cannot reference a rest parameter. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(128,34): error TS1230: A type predicate cannot reference element 'p1' in a binding pattern. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(132,34): error TS1230: A type predicate cannot reference element 'p1' in a binding pattern. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(136,39): error TS1230: A type predicate cannot reference element 'p1' in a binding pattern. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(152,68): error TS2344: Type 'T | "d"' does not satisfy the constraint 'Keys'. +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. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(113,9): error TS2408: Setters cannot return a value. +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. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(122,22): error TS2304: Cannot find name 'p1'. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(122,25): error TS1005: ';' expected. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(122,28): error TS1005: ';' expected. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(123,1): error TS1128: Declaration or statement expected. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(126,20): error TS1229: A type predicate cannot reference a rest parameter. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(131,34): error TS1230: A type predicate cannot reference element 'p1' in a binding pattern. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(135,34): error TS1230: A type predicate cannot reference element 'p1' in a binding pattern. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(139,39): error TS1230: A type predicate cannot reference element 'p1' in a binding pattern. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(155,68): error TS2344: Type 'T | "d"' does not satisfy the constraint 'Keys'. Type '"d"' is not assignable to type 'Keys'. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(159,31): error TS2344: Type 'Bar' does not satisfy the constraint 'Foo'. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(162,31): error TS2344: Type 'Bar' does not satisfy the constraint 'Foo'. Types of property ''a'' are incompatible. Type 'number' is not assignable to type 'string'. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(162,31): error TS2344: Type 'Bar' does not satisfy the constraint 'Foo'. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(163,35): error TS2344: Type 'number' does not satisfy the constraint 'Foo'. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(164,51): error TS2344: Type 'Bar' does not satisfy the constraint 'Foo'. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(165,51): error TS2344: Type 'number' does not satisfy the constraint 'Foo'. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(166,45): error TS2677: A type predicate's type must be assignable to its parameter's type. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(165,31): error TS2344: Type 'Bar' does not satisfy the constraint 'Foo'. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(166,35): error TS2344: Type 'number' does not satisfy the constraint 'Foo'. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(167,51): error TS2344: Type 'Bar' does not satisfy the constraint 'Foo'. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(168,51): error TS2344: Type 'number' does not satisfy the constraint 'Foo'. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(169,45): error TS2677: A type predicate's type must be assignable to its parameter's type. Type 'NeedsFoo' is not assignable to type 'number'. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(166,54): error TS2344: Type 'number' does not satisfy the constraint 'Foo'. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(169,54): error TS2344: Type 'number' does not satisfy the constraint 'Foo'. -==== tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts (56 errors) ==== +==== tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts (57 errors) ==== class A { ~ !!! error TS2300: Duplicate identifier 'A'. @@ -156,6 +159,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(166,54 let a: A; let b: B; + declare function isA(p1): p1 is A; declare function isB(p1): p1 is B; declare function isC(p1): p1 is C; declare function funA(p1: any, p2: any): p1 is B; @@ -186,13 +190,19 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(166,54 } // Type predicate type is not assignable - declare function acceptingDifferentSignatureTypeGuardFunction(p1: (p1) => p1 is B); + declare function acceptingDifferentSignatureTypeGuardFunction(p1: (p1) => p1 is A); acceptingDifferentSignatureTypeGuardFunction(isC); ~~~ -!!! error TS2345: Argument of type '(p1: any) => p1 is C' is not assignable to parameter of type '(p1: any) => p1 is B'. -!!! error TS2345: Type predicate 'p1 is C' is not assignable to 'p1 is B'. -!!! error TS2345: Type 'C' is not assignable to type 'B'. -!!! error TS2345: Property 'propB' is missing in type 'C'. +!!! error TS2345: Argument of type '(p1: any) => p1 is C' is not assignable to parameter of type '(p1: any) => p1 is A'. +!!! error TS2345: Type predicate 'p1 is C' is not assignable to 'p1 is A'. +!!! error TS2345: Type 'A' is not assignable to type 'C'. +!!! error TS2345: Property 'propC' is missing in type 'A'. + declare function acceptingDifferentSignatureTypeGuardFunction2(p1: (p1) => p1 is C); + acceptingDifferentSignatureTypeGuardFunction2(isA); + ~~~ +!!! error TS2345: Argument of type '(p1: any) => p1 is A' is not assignable to parameter of type '(p1: any) => p1 is C'. +!!! error TS2345: Type predicate 'p1 is A' is not assignable to 'p1 is C'. +!!! error TS2345: Type 'A' is not assignable to type 'C'. // Boolean not assignable to type guard var assign1: (p1, p2) => p1 is A; diff --git a/tests/baselines/reference/typeGuardFunctionErrors.js b/tests/baselines/reference/typeGuardFunctionErrors.js index 69eb02229b96b..f43520f619e20 100644 --- a/tests/baselines/reference/typeGuardFunctionErrors.js +++ b/tests/baselines/reference/typeGuardFunctionErrors.js @@ -50,6 +50,7 @@ function hasNonMathcingGenericType(a: string): a is T[] { let a: A; let b: B; +declare function isA(p1): p1 is A; declare function isB(p1): p1 is B; declare function isC(p1): p1 is C; declare function funA(p1: any, p2: any): p1 is B; @@ -71,8 +72,10 @@ if (hasNoTypeGuard(a)) { } // Type predicate type is not assignable -declare function acceptingDifferentSignatureTypeGuardFunction(p1: (p1) => p1 is B); +declare function acceptingDifferentSignatureTypeGuardFunction(p1: (p1) => p1 is A); acceptingDifferentSignatureTypeGuardFunction(isC); +declare function acceptingDifferentSignatureTypeGuardFunction2(p1: (p1) => p1 is C); +acceptingDifferentSignatureTypeGuardFunction2(isA); // Boolean not assignable to type guard var assign1: (p1, p2) => p1 is A; @@ -240,6 +243,7 @@ if (hasNoTypeGuard(a)) { a.propB; } acceptingDifferentSignatureTypeGuardFunction(isC); +acceptingDifferentSignatureTypeGuardFunction2(isA); // Boolean not assignable to type guard var assign1; assign1 = function (p1, p2) { diff --git a/tests/baselines/reference/typeGuardFunctionErrors.symbols b/tests/baselines/reference/typeGuardFunctionErrors.symbols index b51e84c754f25..a69fd3b6a7240 100644 --- a/tests/baselines/reference/typeGuardFunctionErrors.symbols +++ b/tests/baselines/reference/typeGuardFunctionErrors.symbols @@ -34,7 +34,7 @@ function hasTypeGuardTypeInsideTypeGuardType(x): x is x is A { >hasTypeGuardTypeInsideTypeGuardType : Symbol(hasTypeGuardTypeInsideTypeGuardType, Decl(typeGuardFunctionErrors.ts, 14, 1)) >x : Symbol(x, Decl(typeGuardFunctionErrors.ts, 16, 45)) >x : Symbol(x, Decl(typeGuardFunctionErrors.ts, 16, 45)) ->is : Symbol(is, Decl(typeGuardFunctionErrors.ts, 94, 9)) +>is : Symbol(is, Decl(typeGuardFunctionErrors.ts, 97, 9)) >A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 0, 0)) return true; @@ -48,7 +48,7 @@ function hasMissingIsKeyword(): x { function hasMissingParameter(): x is A { >hasMissingParameter : Symbol(hasMissingParameter, Decl(typeGuardFunctionErrors.ts, 22, 1)) ->x : Symbol(x, Decl(typeGuardFunctionErrors.ts, 140, 3)) +>x : Symbol(x, Decl(typeGuardFunctionErrors.ts, 143, 3)) >A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 0, 0)) return true; @@ -65,7 +65,7 @@ function hasMissingTypeInTypeGuardType(x): x is { function hasNonMatchingParameter(y): x is A { >hasNonMatchingParameter : Symbol(hasNonMatchingParameter, Decl(typeGuardFunctionErrors.ts, 30, 1)) >y : Symbol(y, Decl(typeGuardFunctionErrors.ts, 32, 33)) ->x : Symbol(x, Decl(typeGuardFunctionErrors.ts, 140, 3)) +>x : Symbol(x, Decl(typeGuardFunctionErrors.ts, 143, 3)) >A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 0, 0)) return true; @@ -107,32 +107,38 @@ let b: B; >b : Symbol(b, Decl(typeGuardFunctionErrors.ts, 49, 3)) >B : Symbol(B, Decl(typeGuardFunctionErrors.ts, 2, 1)) -declare function isB(p1): p1 is B; ->isB : Symbol(isB, Decl(typeGuardFunctionErrors.ts, 49, 9)) +declare function isA(p1): p1 is A; +>isA : Symbol(isA, Decl(typeGuardFunctionErrors.ts, 49, 9)) >p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 51, 21)) >p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 51, 21)) ->B : Symbol(B, Decl(typeGuardFunctionErrors.ts, 2, 1)) +>A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 0, 0)) -declare function isC(p1): p1 is C; ->isC : Symbol(isC, Decl(typeGuardFunctionErrors.ts, 51, 34)) +declare function isB(p1): p1 is B; +>isB : Symbol(isB, Decl(typeGuardFunctionErrors.ts, 51, 34)) >p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 52, 21)) >p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 52, 21)) +>B : Symbol(B, Decl(typeGuardFunctionErrors.ts, 2, 1)) + +declare function isC(p1): p1 is C; +>isC : Symbol(isC, Decl(typeGuardFunctionErrors.ts, 52, 34)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 53, 21)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 53, 21)) >C : Symbol(C, Decl(typeGuardFunctionErrors.ts, 6, 1)) declare function funA(p1: any, p2: any): p1 is B; ->funA : Symbol(funA, Decl(typeGuardFunctionErrors.ts, 52, 34)) ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 53, 22)) ->p2 : Symbol(p2, Decl(typeGuardFunctionErrors.ts, 53, 30)) ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 53, 22)) +>funA : Symbol(funA, Decl(typeGuardFunctionErrors.ts, 53, 34)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 54, 22)) +>p2 : Symbol(p2, Decl(typeGuardFunctionErrors.ts, 54, 30)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 54, 22)) >B : Symbol(B, Decl(typeGuardFunctionErrors.ts, 2, 1)) declare function hasNoTypeGuard(x); ->hasNoTypeGuard : Symbol(hasNoTypeGuard, Decl(typeGuardFunctionErrors.ts, 53, 49)) ->x : Symbol(x, Decl(typeGuardFunctionErrors.ts, 54, 32)) +>hasNoTypeGuard : Symbol(hasNoTypeGuard, Decl(typeGuardFunctionErrors.ts, 54, 49)) +>x : Symbol(x, Decl(typeGuardFunctionErrors.ts, 55, 32)) // Passed argument is not the same as the one being guarded. if (isB(b)) { ->isB : Symbol(isB, Decl(typeGuardFunctionErrors.ts, 49, 9)) +>isB : Symbol(isB, Decl(typeGuardFunctionErrors.ts, 51, 34)) >b : Symbol(b, Decl(typeGuardFunctionErrors.ts, 49, 3)) a.propB; @@ -141,7 +147,7 @@ if (isB(b)) { // Parameter index and argument index for the type guard target is not matching. if (funA(0, a)) { ->funA : Symbol(funA, Decl(typeGuardFunctionErrors.ts, 52, 34)) +>funA : Symbol(funA, Decl(typeGuardFunctionErrors.ts, 53, 34)) >a : Symbol(a, Decl(typeGuardFunctionErrors.ts, 48, 3)) a.propB; // Error @@ -150,7 +156,7 @@ if (funA(0, a)) { // No type guard in if statement if (hasNoTypeGuard(a)) { ->hasNoTypeGuard : Symbol(hasNoTypeGuard, Decl(typeGuardFunctionErrors.ts, 53, 49)) +>hasNoTypeGuard : Symbol(hasNoTypeGuard, Decl(typeGuardFunctionErrors.ts, 54, 49)) >a : Symbol(a, Decl(typeGuardFunctionErrors.ts, 48, 3)) a.propB; @@ -158,46 +164,57 @@ if (hasNoTypeGuard(a)) { } // Type predicate type is not assignable -declare function acceptingDifferentSignatureTypeGuardFunction(p1: (p1) => p1 is B); ->acceptingDifferentSignatureTypeGuardFunction : Symbol(acceptingDifferentSignatureTypeGuardFunction, Decl(typeGuardFunctionErrors.ts, 69, 1)) ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 72, 62)) ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 72, 67)) ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 72, 67)) ->B : Symbol(B, Decl(typeGuardFunctionErrors.ts, 2, 1)) +declare function acceptingDifferentSignatureTypeGuardFunction(p1: (p1) => p1 is A); +>acceptingDifferentSignatureTypeGuardFunction : Symbol(acceptingDifferentSignatureTypeGuardFunction, Decl(typeGuardFunctionErrors.ts, 70, 1)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 73, 62)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 73, 67)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 73, 67)) +>A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 0, 0)) acceptingDifferentSignatureTypeGuardFunction(isC); ->acceptingDifferentSignatureTypeGuardFunction : Symbol(acceptingDifferentSignatureTypeGuardFunction, Decl(typeGuardFunctionErrors.ts, 69, 1)) ->isC : Symbol(isC, Decl(typeGuardFunctionErrors.ts, 51, 34)) +>acceptingDifferentSignatureTypeGuardFunction : Symbol(acceptingDifferentSignatureTypeGuardFunction, Decl(typeGuardFunctionErrors.ts, 70, 1)) +>isC : Symbol(isC, Decl(typeGuardFunctionErrors.ts, 52, 34)) + +declare function acceptingDifferentSignatureTypeGuardFunction2(p1: (p1) => p1 is C); +>acceptingDifferentSignatureTypeGuardFunction2 : Symbol(acceptingDifferentSignatureTypeGuardFunction2, Decl(typeGuardFunctionErrors.ts, 74, 50)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 75, 63)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 75, 68)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 75, 68)) +>C : Symbol(C, Decl(typeGuardFunctionErrors.ts, 6, 1)) + +acceptingDifferentSignatureTypeGuardFunction2(isA); +>acceptingDifferentSignatureTypeGuardFunction2 : Symbol(acceptingDifferentSignatureTypeGuardFunction2, Decl(typeGuardFunctionErrors.ts, 74, 50)) +>isA : Symbol(isA, Decl(typeGuardFunctionErrors.ts, 49, 9)) // Boolean not assignable to type guard var assign1: (p1, p2) => p1 is A; ->assign1 : Symbol(assign1, Decl(typeGuardFunctionErrors.ts, 76, 3)) ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 76, 14)) ->p2 : Symbol(p2, Decl(typeGuardFunctionErrors.ts, 76, 17)) ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 76, 14)) +>assign1 : Symbol(assign1, Decl(typeGuardFunctionErrors.ts, 79, 3)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 79, 14)) +>p2 : Symbol(p2, Decl(typeGuardFunctionErrors.ts, 79, 17)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 79, 14)) >A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 0, 0)) assign1 = function(p1, p2): boolean { ->assign1 : Symbol(assign1, Decl(typeGuardFunctionErrors.ts, 76, 3)) ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 77, 19)) ->p2 : Symbol(p2, Decl(typeGuardFunctionErrors.ts, 77, 22)) +>assign1 : Symbol(assign1, Decl(typeGuardFunctionErrors.ts, 79, 3)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 80, 19)) +>p2 : Symbol(p2, Decl(typeGuardFunctionErrors.ts, 80, 22)) return true; }; // Must have matching parameter index var assign2: (p1, p2) => p1 is A; ->assign2 : Symbol(assign2, Decl(typeGuardFunctionErrors.ts, 82, 3)) ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 82, 14)) ->p2 : Symbol(p2, Decl(typeGuardFunctionErrors.ts, 82, 17)) ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 82, 14)) +>assign2 : Symbol(assign2, Decl(typeGuardFunctionErrors.ts, 85, 3)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 85, 14)) +>p2 : Symbol(p2, Decl(typeGuardFunctionErrors.ts, 85, 17)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 85, 14)) >A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 0, 0)) assign2 = function(p1, p2): p2 is A { ->assign2 : Symbol(assign2, Decl(typeGuardFunctionErrors.ts, 82, 3)) ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 83, 19)) ->p2 : Symbol(p2, Decl(typeGuardFunctionErrors.ts, 83, 22)) ->p2 : Symbol(p2, Decl(typeGuardFunctionErrors.ts, 83, 22)) +>assign2 : Symbol(assign2, Decl(typeGuardFunctionErrors.ts, 85, 3)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 86, 19)) +>p2 : Symbol(p2, Decl(typeGuardFunctionErrors.ts, 86, 22)) +>p2 : Symbol(p2, Decl(typeGuardFunctionErrors.ts, 86, 22)) >A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 0, 0)) return true; @@ -205,18 +222,18 @@ assign2 = function(p1, p2): p2 is A { // No matching signature var assign3: (p1, p2) => p1 is A; ->assign3 : Symbol(assign3, Decl(typeGuardFunctionErrors.ts, 88, 3)) ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 88, 14)) ->p2 : Symbol(p2, Decl(typeGuardFunctionErrors.ts, 88, 17)) ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 88, 14)) +>assign3 : Symbol(assign3, Decl(typeGuardFunctionErrors.ts, 91, 3)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 91, 14)) +>p2 : Symbol(p2, Decl(typeGuardFunctionErrors.ts, 91, 17)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 91, 14)) >A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 0, 0)) assign3 = function(p1, p2, p3): p1 is A { ->assign3 : Symbol(assign3, Decl(typeGuardFunctionErrors.ts, 88, 3)) ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 89, 19)) ->p2 : Symbol(p2, Decl(typeGuardFunctionErrors.ts, 89, 22)) ->p3 : Symbol(p3, Decl(typeGuardFunctionErrors.ts, 89, 26)) ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 89, 19)) +>assign3 : Symbol(assign3, Decl(typeGuardFunctionErrors.ts, 91, 3)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 92, 19)) +>p2 : Symbol(p2, Decl(typeGuardFunctionErrors.ts, 92, 22)) +>p3 : Symbol(p3, Decl(typeGuardFunctionErrors.ts, 92, 26)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 92, 19)) >A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 0, 0)) return true; @@ -224,20 +241,20 @@ assign3 = function(p1, p2, p3): p1 is A { // Type predicates in non-return type positions var b1: b is A; ->b1 : Symbol(b1, Decl(typeGuardFunctionErrors.ts, 94, 3)) ->is : Symbol(is, Decl(typeGuardFunctionErrors.ts, 94, 9)) ->A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 94, 12)) +>b1 : Symbol(b1, Decl(typeGuardFunctionErrors.ts, 97, 3)) +>is : Symbol(is, Decl(typeGuardFunctionErrors.ts, 97, 9)) +>A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 97, 12)) function b2(a: b is A) {}; ->b2 : Symbol(b2, Decl(typeGuardFunctionErrors.ts, 94, 15)) ->a : Symbol(a, Decl(typeGuardFunctionErrors.ts, 95, 12)) ->is : Symbol(is, Decl(typeGuardFunctionErrors.ts, 95, 16)) ->A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 95, 19)) +>b2 : Symbol(b2, Decl(typeGuardFunctionErrors.ts, 97, 15)) +>a : Symbol(a, Decl(typeGuardFunctionErrors.ts, 98, 12)) +>is : Symbol(is, Decl(typeGuardFunctionErrors.ts, 98, 16)) +>A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 98, 19)) function b3(): A | b is A { ->b3 : Symbol(b3, Decl(typeGuardFunctionErrors.ts, 95, 26)) +>b3 : Symbol(b3, Decl(typeGuardFunctionErrors.ts, 98, 26)) >A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 0, 0)) ->is : Symbol(is, Decl(typeGuardFunctionErrors.ts, 94, 9)) +>is : Symbol(is, Decl(typeGuardFunctionErrors.ts, 97, 9)) >A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 0, 0)) return true; @@ -245,30 +262,30 @@ function b3(): A | b is A { // Non-compatiable type predicate positions for signature declarations class D { ->D : Symbol(D, Decl(typeGuardFunctionErrors.ts, 98, 2)) +>D : Symbol(D, Decl(typeGuardFunctionErrors.ts, 101, 2)) constructor(p1: A): p1 is C { ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 102, 16)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 105, 16)) >A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 0, 0)) ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 102, 16)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 105, 16)) >C : Symbol(C, Decl(typeGuardFunctionErrors.ts, 6, 1)) return true; } get m1(p1: A): p1 is C { ->m1 : Symbol(D.m1, Decl(typeGuardFunctionErrors.ts, 104, 5)) ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 105, 11)) +>m1 : Symbol(D.m1, Decl(typeGuardFunctionErrors.ts, 107, 5)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 108, 11)) >A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 0, 0)) ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 105, 11)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 108, 11)) >C : Symbol(C, Decl(typeGuardFunctionErrors.ts, 6, 1)) return true; } set m2(p1: A): p1 is C { ->m2 : Symbol(D.m2, Decl(typeGuardFunctionErrors.ts, 107, 5)) ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 108, 11)) +>m2 : Symbol(D.m2, Decl(typeGuardFunctionErrors.ts, 110, 5)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 111, 11)) >A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 0, 0)) ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 108, 11)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 111, 11)) >C : Symbol(C, Decl(typeGuardFunctionErrors.ts, 6, 1)) return true; @@ -276,29 +293,29 @@ class D { } interface I1 { ->I1 : Symbol(I1, Decl(typeGuardFunctionErrors.ts, 111, 1)) +>I1 : Symbol(I1, Decl(typeGuardFunctionErrors.ts, 114, 1)) new (p1: A): p1 is C; ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 114, 9)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 117, 9)) >A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 0, 0)) ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 114, 9)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 117, 9)) >C : Symbol(C, Decl(typeGuardFunctionErrors.ts, 6, 1)) } interface I2 { ->I2 : Symbol(I2, Decl(typeGuardFunctionErrors.ts, 115, 1)) +>I2 : Symbol(I2, Decl(typeGuardFunctionErrors.ts, 118, 1)) [index: number]: p1 is C; ->index : Symbol(index, Decl(typeGuardFunctionErrors.ts, 118, 5)) ->is : Symbol(is, Decl(typeGuardFunctionErrors.ts, 94, 9)) +>index : Symbol(index, Decl(typeGuardFunctionErrors.ts, 121, 5)) +>is : Symbol(is, Decl(typeGuardFunctionErrors.ts, 97, 9)) >C : Symbol(C, Decl(typeGuardFunctionErrors.ts, 6, 1)) } // Reference to rest parameter function b4(...a): a is A { ->b4 : Symbol(b4, Decl(typeGuardFunctionErrors.ts, 119, 1)) ->a : Symbol(a, Decl(typeGuardFunctionErrors.ts, 122, 12)) ->a : Symbol(a, Decl(typeGuardFunctionErrors.ts, 122, 12)) +>b4 : Symbol(b4, Decl(typeGuardFunctionErrors.ts, 122, 1)) +>a : Symbol(a, Decl(typeGuardFunctionErrors.ts, 125, 12)) +>a : Symbol(a, Decl(typeGuardFunctionErrors.ts, 125, 12)) >A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 0, 0)) return true; @@ -306,40 +323,40 @@ function b4(...a): a is A { // Reference to binding pattern function b5({a, b, p1}, p2, p3): p1 is A { ->b5 : Symbol(b5, Decl(typeGuardFunctionErrors.ts, 124, 1)) ->a : Symbol(a, Decl(typeGuardFunctionErrors.ts, 127, 13)) ->b : Symbol(b, Decl(typeGuardFunctionErrors.ts, 127, 15)) ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 127, 18)) ->p2 : Symbol(p2, Decl(typeGuardFunctionErrors.ts, 127, 23)) ->p3 : Symbol(p3, Decl(typeGuardFunctionErrors.ts, 127, 27)) ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 127, 18)) +>b5 : Symbol(b5, Decl(typeGuardFunctionErrors.ts, 127, 1)) +>a : Symbol(a, Decl(typeGuardFunctionErrors.ts, 130, 13)) +>b : Symbol(b, Decl(typeGuardFunctionErrors.ts, 130, 15)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 130, 18)) +>p2 : Symbol(p2, Decl(typeGuardFunctionErrors.ts, 130, 23)) +>p3 : Symbol(p3, Decl(typeGuardFunctionErrors.ts, 130, 27)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 130, 18)) >A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 0, 0)) return true; } function b6([a, b, p1], p2, p3): p1 is A { ->b6 : Symbol(b6, Decl(typeGuardFunctionErrors.ts, 129, 1)) ->a : Symbol(a, Decl(typeGuardFunctionErrors.ts, 131, 13)) ->b : Symbol(b, Decl(typeGuardFunctionErrors.ts, 131, 15)) ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 131, 18)) ->p2 : Symbol(p2, Decl(typeGuardFunctionErrors.ts, 131, 23)) ->p3 : Symbol(p3, Decl(typeGuardFunctionErrors.ts, 131, 27)) ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 131, 18)) +>b6 : Symbol(b6, Decl(typeGuardFunctionErrors.ts, 132, 1)) +>a : Symbol(a, Decl(typeGuardFunctionErrors.ts, 134, 13)) +>b : Symbol(b, Decl(typeGuardFunctionErrors.ts, 134, 15)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 134, 18)) +>p2 : Symbol(p2, Decl(typeGuardFunctionErrors.ts, 134, 23)) +>p3 : Symbol(p3, Decl(typeGuardFunctionErrors.ts, 134, 27)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 134, 18)) >A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 0, 0)) return true; } function b7({a, b, c: {p1}}, p2, p3): p1 is A { ->b7 : Symbol(b7, Decl(typeGuardFunctionErrors.ts, 133, 1)) ->a : Symbol(a, Decl(typeGuardFunctionErrors.ts, 135, 13)) ->b : Symbol(b, Decl(typeGuardFunctionErrors.ts, 135, 15)) +>b7 : Symbol(b7, Decl(typeGuardFunctionErrors.ts, 136, 1)) +>a : Symbol(a, Decl(typeGuardFunctionErrors.ts, 138, 13)) +>b : Symbol(b, Decl(typeGuardFunctionErrors.ts, 138, 15)) >c : Symbol(c) ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 135, 23)) ->p2 : Symbol(p2, Decl(typeGuardFunctionErrors.ts, 135, 28)) ->p3 : Symbol(p3, Decl(typeGuardFunctionErrors.ts, 135, 32)) ->p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 135, 23)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 138, 23)) +>p2 : Symbol(p2, Decl(typeGuardFunctionErrors.ts, 138, 28)) +>p3 : Symbol(p3, Decl(typeGuardFunctionErrors.ts, 138, 32)) +>p1 : Symbol(p1, Decl(typeGuardFunctionErrors.ts, 138, 23)) >A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 0, 0)) return true; @@ -347,7 +364,7 @@ function b7({a, b, c: {p1}}, p2, p3): p1 is A { // Should not crash the compiler var x: A; ->x : Symbol(x, Decl(typeGuardFunctionErrors.ts, 140, 3)) +>x : Symbol(x, Decl(typeGuardFunctionErrors.ts, 143, 3)) >A : Symbol(A, Decl(typeGuardFunctionErrors.ts, 0, 0)) if (hasMissingParameter()) { @@ -355,83 +372,83 @@ if (hasMissingParameter()) { x.propA; >x.propA : Symbol(A.propA, Decl(typeGuardFunctionErrors.ts, 0, 9)) ->x : Symbol(x, Decl(typeGuardFunctionErrors.ts, 140, 3)) +>x : Symbol(x, Decl(typeGuardFunctionErrors.ts, 143, 3)) >propA : Symbol(A.propA, Decl(typeGuardFunctionErrors.ts, 0, 9)) } // repro #17297 type Keys = 'a'|'b'|'c' ->Keys : Symbol(Keys, Decl(typeGuardFunctionErrors.ts, 143, 1)) +>Keys : Symbol(Keys, Decl(typeGuardFunctionErrors.ts, 146, 1)) type KeySet = { [k in T]: true } ->KeySet : Symbol(KeySet, Decl(typeGuardFunctionErrors.ts, 147, 23)) ->T : Symbol(T, Decl(typeGuardFunctionErrors.ts, 148, 12)) ->Keys : Symbol(Keys, Decl(typeGuardFunctionErrors.ts, 143, 1)) ->k : Symbol(k, Decl(typeGuardFunctionErrors.ts, 148, 33)) ->T : Symbol(T, Decl(typeGuardFunctionErrors.ts, 148, 12)) +>KeySet : Symbol(KeySet, Decl(typeGuardFunctionErrors.ts, 150, 23)) +>T : Symbol(T, Decl(typeGuardFunctionErrors.ts, 151, 12)) +>Keys : Symbol(Keys, Decl(typeGuardFunctionErrors.ts, 146, 1)) +>k : Symbol(k, Decl(typeGuardFunctionErrors.ts, 151, 33)) +>T : Symbol(T, Decl(typeGuardFunctionErrors.ts, 151, 12)) // expected an error, since Keys doesn't have a 'd' declare function hasKey(x: KeySet): x is KeySet; ->hasKey : Symbol(hasKey, Decl(typeGuardFunctionErrors.ts, 148, 48)) ->T : Symbol(T, Decl(typeGuardFunctionErrors.ts, 151, 24)) ->Keys : Symbol(Keys, Decl(typeGuardFunctionErrors.ts, 143, 1)) ->x : Symbol(x, Decl(typeGuardFunctionErrors.ts, 151, 40)) ->KeySet : Symbol(KeySet, Decl(typeGuardFunctionErrors.ts, 147, 23)) ->T : Symbol(T, Decl(typeGuardFunctionErrors.ts, 151, 24)) ->x : Symbol(x, Decl(typeGuardFunctionErrors.ts, 151, 40)) ->KeySet : Symbol(KeySet, Decl(typeGuardFunctionErrors.ts, 147, 23)) ->T : Symbol(T, Decl(typeGuardFunctionErrors.ts, 151, 24)) +>hasKey : Symbol(hasKey, Decl(typeGuardFunctionErrors.ts, 151, 48)) +>T : Symbol(T, Decl(typeGuardFunctionErrors.ts, 154, 24)) +>Keys : Symbol(Keys, Decl(typeGuardFunctionErrors.ts, 146, 1)) +>x : Symbol(x, Decl(typeGuardFunctionErrors.ts, 154, 40)) +>KeySet : Symbol(KeySet, Decl(typeGuardFunctionErrors.ts, 150, 23)) +>T : Symbol(T, Decl(typeGuardFunctionErrors.ts, 154, 24)) +>x : Symbol(x, Decl(typeGuardFunctionErrors.ts, 154, 40)) +>KeySet : Symbol(KeySet, Decl(typeGuardFunctionErrors.ts, 150, 23)) +>T : Symbol(T, Decl(typeGuardFunctionErrors.ts, 154, 24)) type Foo = { 'a': string; } ->Foo : Symbol(Foo, Decl(typeGuardFunctionErrors.ts, 151, 74)) ->'a' : Symbol('a', Decl(typeGuardFunctionErrors.ts, 153, 12)) +>Foo : Symbol(Foo, Decl(typeGuardFunctionErrors.ts, 154, 74)) +>'a' : Symbol('a', Decl(typeGuardFunctionErrors.ts, 156, 12)) type Bar = { 'a': number; } ->Bar : Symbol(Bar, Decl(typeGuardFunctionErrors.ts, 153, 27)) ->'a' : Symbol('a', Decl(typeGuardFunctionErrors.ts, 154, 12)) +>Bar : Symbol(Bar, Decl(typeGuardFunctionErrors.ts, 156, 27)) +>'a' : Symbol('a', Decl(typeGuardFunctionErrors.ts, 157, 12)) interface NeedsFoo { ->NeedsFoo : Symbol(NeedsFoo, Decl(typeGuardFunctionErrors.ts, 154, 27)) ->T : Symbol(T, Decl(typeGuardFunctionErrors.ts, 156, 19)) ->Foo : Symbol(Foo, Decl(typeGuardFunctionErrors.ts, 151, 74)) +>NeedsFoo : Symbol(NeedsFoo, Decl(typeGuardFunctionErrors.ts, 157, 27)) +>T : Symbol(T, Decl(typeGuardFunctionErrors.ts, 159, 19)) +>Foo : Symbol(Foo, Decl(typeGuardFunctionErrors.ts, 154, 74)) foo: T; ->foo : Symbol(NeedsFoo.foo, Decl(typeGuardFunctionErrors.ts, 156, 35)) ->T : Symbol(T, Decl(typeGuardFunctionErrors.ts, 156, 19)) +>foo : Symbol(NeedsFoo.foo, Decl(typeGuardFunctionErrors.ts, 159, 35)) +>T : Symbol(T, Decl(typeGuardFunctionErrors.ts, 159, 19)) isFoo(): this is NeedsFoo; // should error ->isFoo : Symbol(NeedsFoo.isFoo, Decl(typeGuardFunctionErrors.ts, 157, 11)) ->NeedsFoo : Symbol(NeedsFoo, Decl(typeGuardFunctionErrors.ts, 154, 27)) ->Bar : Symbol(Bar, Decl(typeGuardFunctionErrors.ts, 153, 27)) +>isFoo : Symbol(NeedsFoo.isFoo, Decl(typeGuardFunctionErrors.ts, 160, 11)) +>NeedsFoo : Symbol(NeedsFoo, Decl(typeGuardFunctionErrors.ts, 157, 27)) +>Bar : Symbol(Bar, Decl(typeGuardFunctionErrors.ts, 156, 27)) }; declare var anError: NeedsFoo; // error, as expected ->anError : Symbol(anError, Decl(typeGuardFunctionErrors.ts, 161, 11)) ->NeedsFoo : Symbol(NeedsFoo, Decl(typeGuardFunctionErrors.ts, 154, 27)) ->Bar : Symbol(Bar, Decl(typeGuardFunctionErrors.ts, 153, 27)) +>anError : Symbol(anError, Decl(typeGuardFunctionErrors.ts, 164, 11)) +>NeedsFoo : Symbol(NeedsFoo, Decl(typeGuardFunctionErrors.ts, 157, 27)) +>Bar : Symbol(Bar, Decl(typeGuardFunctionErrors.ts, 156, 27)) declare var alsoAnError: NeedsFoo; // also error, as expected ->alsoAnError : Symbol(alsoAnError, Decl(typeGuardFunctionErrors.ts, 162, 11)) ->NeedsFoo : Symbol(NeedsFoo, Decl(typeGuardFunctionErrors.ts, 154, 27)) +>alsoAnError : Symbol(alsoAnError, Decl(typeGuardFunctionErrors.ts, 165, 11)) +>NeedsFoo : Symbol(NeedsFoo, Decl(typeGuardFunctionErrors.ts, 157, 27)) declare function newError1(x: any): x is NeedsFoo; // should error ->newError1 : Symbol(newError1, Decl(typeGuardFunctionErrors.ts, 162, 42)) ->x : Symbol(x, Decl(typeGuardFunctionErrors.ts, 163, 27)) ->x : Symbol(x, Decl(typeGuardFunctionErrors.ts, 163, 27)) ->NeedsFoo : Symbol(NeedsFoo, Decl(typeGuardFunctionErrors.ts, 154, 27)) ->Bar : Symbol(Bar, Decl(typeGuardFunctionErrors.ts, 153, 27)) +>newError1 : Symbol(newError1, Decl(typeGuardFunctionErrors.ts, 165, 42)) +>x : Symbol(x, Decl(typeGuardFunctionErrors.ts, 166, 27)) +>x : Symbol(x, Decl(typeGuardFunctionErrors.ts, 166, 27)) +>NeedsFoo : Symbol(NeedsFoo, Decl(typeGuardFunctionErrors.ts, 157, 27)) +>Bar : Symbol(Bar, Decl(typeGuardFunctionErrors.ts, 156, 27)) declare function newError2(x: any): x is NeedsFoo; // should error ->newError2 : Symbol(newError2, Decl(typeGuardFunctionErrors.ts, 163, 55)) ->x : Symbol(x, Decl(typeGuardFunctionErrors.ts, 164, 27)) ->x : Symbol(x, Decl(typeGuardFunctionErrors.ts, 164, 27)) ->NeedsFoo : Symbol(NeedsFoo, Decl(typeGuardFunctionErrors.ts, 154, 27)) +>newError2 : Symbol(newError2, Decl(typeGuardFunctionErrors.ts, 166, 55)) +>x : Symbol(x, Decl(typeGuardFunctionErrors.ts, 167, 27)) +>x : Symbol(x, Decl(typeGuardFunctionErrors.ts, 167, 27)) +>NeedsFoo : Symbol(NeedsFoo, Decl(typeGuardFunctionErrors.ts, 157, 27)) declare function newError3(x: number): x is NeedsFoo; // should error ->newError3 : Symbol(newError3, Decl(typeGuardFunctionErrors.ts, 164, 58)) ->x : Symbol(x, Decl(typeGuardFunctionErrors.ts, 165, 27)) ->x : Symbol(x, Decl(typeGuardFunctionErrors.ts, 165, 27)) ->NeedsFoo : Symbol(NeedsFoo, Decl(typeGuardFunctionErrors.ts, 154, 27)) +>newError3 : Symbol(newError3, Decl(typeGuardFunctionErrors.ts, 167, 58)) +>x : Symbol(x, Decl(typeGuardFunctionErrors.ts, 168, 27)) +>x : Symbol(x, Decl(typeGuardFunctionErrors.ts, 168, 27)) +>NeedsFoo : Symbol(NeedsFoo, Decl(typeGuardFunctionErrors.ts, 157, 27)) diff --git a/tests/baselines/reference/typeGuardFunctionErrors.types b/tests/baselines/reference/typeGuardFunctionErrors.types index 5d5639f8a2c3c..1a4712b7950f0 100644 --- a/tests/baselines/reference/typeGuardFunctionErrors.types +++ b/tests/baselines/reference/typeGuardFunctionErrors.types @@ -99,6 +99,10 @@ let a: A; let b: B; >b : B +declare function isA(p1): p1 is A; +>isA : (p1: any) => p1 is A +>p1 : any + declare function isB(p1): p1 is B; >isB : (p1: any) => p1 is B >p1 : any @@ -154,16 +158,26 @@ if (hasNoTypeGuard(a)) { } // Type predicate type is not assignable -declare function acceptingDifferentSignatureTypeGuardFunction(p1: (p1) => p1 is B); ->acceptingDifferentSignatureTypeGuardFunction : (p1: (p1: any) => p1 is B) => any ->p1 : (p1: any) => p1 is B +declare function acceptingDifferentSignatureTypeGuardFunction(p1: (p1) => p1 is A); +>acceptingDifferentSignatureTypeGuardFunction : (p1: (p1: any) => p1 is A) => any +>p1 : (p1: any) => p1 is A >p1 : any acceptingDifferentSignatureTypeGuardFunction(isC); >acceptingDifferentSignatureTypeGuardFunction(isC) : any ->acceptingDifferentSignatureTypeGuardFunction : (p1: (p1: any) => p1 is B) => any +>acceptingDifferentSignatureTypeGuardFunction : (p1: (p1: any) => p1 is A) => any >isC : (p1: any) => p1 is C +declare function acceptingDifferentSignatureTypeGuardFunction2(p1: (p1) => p1 is C); +>acceptingDifferentSignatureTypeGuardFunction2 : (p1: (p1: any) => p1 is C) => any +>p1 : (p1: any) => p1 is C +>p1 : any + +acceptingDifferentSignatureTypeGuardFunction2(isA); +>acceptingDifferentSignatureTypeGuardFunction2(isA) : any +>acceptingDifferentSignatureTypeGuardFunction2 : (p1: (p1: any) => p1 is C) => any +>isA : (p1: any) => p1 is A + // Boolean not assignable to type guard var assign1: (p1, p2) => p1 is A; >assign1 : (p1: any, p2: any) => p1 is A diff --git a/tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts b/tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts index eb61473c5ccad..89c9107ff1732 100644 --- a/tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts +++ b/tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts @@ -50,6 +50,7 @@ function hasNonMathcingGenericType(a: string): a is T[] { let a: A; let b: B; +declare function isA(p1): p1 is A; declare function isB(p1): p1 is B; declare function isC(p1): p1 is C; declare function funA(p1: any, p2: any): p1 is B; @@ -71,8 +72,10 @@ if (hasNoTypeGuard(a)) { } // Type predicate type is not assignable -declare function acceptingDifferentSignatureTypeGuardFunction(p1: (p1) => p1 is B); +declare function acceptingDifferentSignatureTypeGuardFunction(p1: (p1) => p1 is A); acceptingDifferentSignatureTypeGuardFunction(isC); +declare function acceptingDifferentSignatureTypeGuardFunction2(p1: (p1) => p1 is C); +acceptingDifferentSignatureTypeGuardFunction2(isA); // Boolean not assignable to type guard var assign1: (p1, p2) => p1 is A; diff --git a/tests/cases/fourslash/thisPredicateFunctionQuickInfo01.ts b/tests/cases/fourslash/thisPredicateFunctionQuickInfo01.ts index 153e5aa639066..76855be2f7d42 100644 --- a/tests/cases/fourslash/thisPredicateFunctionQuickInfo01.ts +++ b/tests/cases/fourslash/thisPredicateFunctionQuickInfo01.ts @@ -7,7 +7,12 @@ //// /*2*/isDirectory(): this is Directory { //// return this instanceof Directory; //// } -//// /*3*/isNetworked(): this is (Networked & this) { +//// // If we just write `isNetworked(): this is (Networked & this)`, then +//// // we have `this` in a non-covariant position, which breaks +//// // assignability of subclasses to `FileSystemObject`. The following is +//// // a workaround that should be equivalent from the caller's point of +//// // view. +//// /*3*/isNetworked(this: T): this is (Networked & T) { //// return !!(this as Networked).host; //// } //// constructor(public path: string) {} @@ -43,11 +48,11 @@ verify.quickInfos({ 1: "(method) FileSystemObject.isFile(): this is Item", 2: "(method) FileSystemObject.isDirectory(): this is Directory", - 3: "(method) FileSystemObject.isNetworked(): this is Networked & this", + 3: "(method) FileSystemObject.isNetworked(this: T): this is Networked & T", 4: "(method) FileSystemObject.isFile(): this is Item", - 5: "(method) FileSystemObject.isNetworked(): this is Networked & Item", + 5: "(method) FileSystemObject.isNetworked(this: Item): this is Networked & Item", 6: "(method) FileSystemObject.isDirectory(): this is Directory", - 7: "(method) FileSystemObject.isNetworked(): this is Networked & Directory", - 8: "(method) FileSystemObject.isNetworked(): this is Networked & FileSystemObject" + 7: "(method) FileSystemObject.isNetworked(this: Directory): this is Networked & Directory", + 8: "(method) FileSystemObject.isNetworked(this: FileSystemObject): this is Networked & FileSystemObject" });