diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4514834a9ff..af1e9349eee 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8588,7 +8588,6 @@ module ts { } function getTypePredicateParameterIndex(parameterList: NodeArray, parameter: Identifier): number { - let index = -1; if (parameterList) { for (let i = 0; i < parameterList.length; i++) { let param = parameterList[i]; @@ -8599,6 +8598,7 @@ module ts { } } } + return -1; } function isInLegalTypePredicatePosition(node: Node): boolean { @@ -8639,7 +8639,7 @@ module ts { if (typePredicate.parameterIndex >= 0) { if (node.parameters[typePredicate.parameterIndex].dotDotDotToken) { error(typePredicateNode.parameterName, - Diagnostics.Type_predicate_cannot_reference_a_rest_parameter); + Diagnostics.A_type_predicate_cannot_reference_a_rest_parameter); } else { checkTypeAssignableTo(typePredicate.type, @@ -8656,24 +8656,24 @@ module ts { if (param.name.kind === SyntaxKind.ObjectBindingPattern || param.name.kind === SyntaxKind.ArrayBindingPattern) { - (function checkBindingPattern(elements: NodeArray) { - for (let element of elements) { + (function checkBindingPattern(pattern: BindingPattern) { + for (let element of pattern.elements) { if (element.name.kind === SyntaxKind.Identifier && (element.name).text === typePredicate.parameterName) { error(typePredicateNode.parameterName, - Diagnostics.Type_predicate_cannot_reference_element_0_in_a_binding_pattern, + Diagnostics.A_type_predicate_cannot_reference_element_0_in_a_binding_pattern, typePredicate.parameterName); hasReportedError = true; break; } - else if(element.name.kind === SyntaxKind.ArrayBindingPattern || + else if (element.name.kind === SyntaxKind.ArrayBindingPattern || element.name.kind === SyntaxKind.ObjectBindingPattern) { - checkBindingPattern((element.name).elements); + checkBindingPattern(element.name); } } - })((param.name).elements); + })(param.name); } } if (!hasReportedError) { @@ -8685,7 +8685,7 @@ module ts { } else { error(typePredicateNode, - Diagnostics.Type_predicate_are_only_allowed_in_return_type_position_for_functions_and_methods); + Diagnostics.A_type_predicate_is_only_allowed_in_return_type_position_for_functions_and_methods); } } else { @@ -11327,7 +11327,7 @@ module ts { function checkTypePredicate(node: TypePredicateNode) { if(!isInLegalTypePredicatePosition(node)) { - error(node, Diagnostics.Type_predicate_are_only_allowed_in_return_type_position_for_functions_and_methods); + error(node, Diagnostics.A_type_predicate_is_only_allowed_in_return_type_position_for_functions_and_methods); } } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 1a79f4b2f44..51a955ea59c 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -183,9 +183,9 @@ module ts { Cannot_find_parameter_0: { code: 1225, category: DiagnosticCategory.Error, key: "Cannot find parameter '{0}'." }, Type_predicate_0_is_not_assignable_to_1: { code: 1226, category: DiagnosticCategory.Error, key: "Type predicate '{0}' is not assignable to '{1}'." }, Parameter_0_is_not_in_the_same_position_as_parameter_1: { code: 1227, category: DiagnosticCategory.Error, key: "Parameter '{0}' is not in the same position as parameter '{1}'." }, - Type_predicate_are_only_allowed_in_return_type_position_for_functions_and_methods: { code: 1228, category: DiagnosticCategory.Error, key: "Type predicate are only allowed in return type position for functions and methods." }, - Type_predicate_cannot_reference_a_rest_parameter: { code: 1229, category: DiagnosticCategory.Error, key: "Type predicate cannot reference a rest parameter." }, - Type_predicate_cannot_reference_element_0_in_a_binding_pattern: { code: 1230, category: DiagnosticCategory.Error, key: "Type predicate cannot reference element '{0}' in a binding pattern." }, + A_type_predicate_is_only_allowed_in_return_type_position_for_functions_and_methods: { code: 1228, category: DiagnosticCategory.Error, key: "A type predicate is only allowed in return type position for functions and methods." }, + A_type_predicate_cannot_reference_a_rest_parameter: { code: 1229, category: DiagnosticCategory.Error, key: "A type predicate cannot reference a rest parameter." }, + A_type_predicate_cannot_reference_element_0_in_a_binding_pattern: { code: 1230, category: DiagnosticCategory.Error, key: "A type predicate cannot reference element '{0}' in a binding pattern." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 6ffc62a66ee..567ccd86303 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -719,15 +719,15 @@ "category": "Error", "code": 1227 }, - "Type predicate are only allowed in return type position for functions and methods.": { + "A type predicate is only allowed in return type position for functions and methods.": { "category": "Error", "code": 1228 }, - "Type predicate cannot reference a rest parameter.": { + "A type predicate cannot reference a rest parameter.": { "category": "Error", "code": 1229 }, - "Type predicate cannot reference element '{0}' in a binding pattern.": { + "A type predicate cannot reference element '{0}' in a binding pattern.": { "category": "Error", "code": 1230 }, diff --git a/tests/baselines/reference/typeGuardFunctionErrors.errors.txt b/tests/baselines/reference/typeGuardFunctionErrors.errors.txt index 7fa26b41217..1542bbe0fee 100644 --- a/tests/baselines/reference/typeGuardFunctionErrors.errors.txt +++ b/tests/baselines/reference/typeGuardFunctionErrors.errors.txt @@ -20,20 +20,20 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(81,1): 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(87,1): error TS2322: Type '(p1: any, p2: any, p3: any) => boolean' is not assignable to type '(p1: any, p2: any) => boolean'. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(92,9): error TS1228: Type predicate are only allowed in return type position for functions and methods. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(93,16): error TS1228: Type predicate are only allowed in return type position for functions and methods. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(94,20): error TS1228: Type predicate are only allowed in return type position for functions and methods. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(100,25): error TS1228: Type predicate are only allowed in return type position for functions and methods. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(92,9): error TS1228: A type predicate is only allowed in return type position for functions and methods. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(93,16): error TS1228: A type predicate is only allowed in return type position for functions and methods. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(94,20): error TS1228: A type predicate is only allowed in return type position for functions and methods. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(100,25): error TS1228: A type predicate is only allowed in return type position for functions and methods. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(101,16): error TS2409: Return type of constructor signature must be assignable to the instance type of the class -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(103,20): error TS1228: Type predicate are only allowed in return type position for functions and methods. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(106,20): error TS1228: Type predicate are only allowed in return type position for functions and methods. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(103,20): error TS1228: A type predicate is only allowed in return type position for functions and methods. +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(107,16): error TS2408: Setters cannot return a value. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(112,18): error TS1228: Type predicate are only allowed in return type position for functions and methods. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(116,22): error TS1228: Type predicate are only allowed in return type position for functions and methods. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(120,20): error TS1229: Type predicate cannot reference a rest parameter. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(125,34): error TS1230: Type predicate cannot reference element 'p1' in a binding pattern. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(129,34): error TS1230: Type predicate cannot reference element 'p1' in a binding pattern. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(133,39): error TS1230: Type predicate cannot reference element 'p1' in a binding pattern. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(112,18): error TS1228: A type predicate is only allowed in return type position for functions and methods. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(116,22): error TS1228: A type predicate is only allowed in return type position for functions and methods. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(120,20): error TS1229: A type predicate cannot reference a rest parameter. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(125,34): error TS1230: A type predicate cannot reference element 'p1' in a binding pattern. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(129,34): error TS1230: A type predicate cannot reference element 'p1' in a binding pattern. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(133,39): error TS1230: A type predicate cannot reference element 'p1' in a binding pattern. ==== tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts (30 errors) ==== @@ -168,13 +168,13 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(133,39 // Type predicates in non-return type positions var b1: b is A; ~~~~~~ -!!! error TS1228: Type predicate are only allowed in return type position for functions and methods. +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. function b2(a: b is A) {}; ~~~~~~ -!!! error TS1228: Type predicate are only allowed in return type position for functions and methods. +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. function b3(): A | b is A { ~~~~~~ -!!! error TS1228: Type predicate are only allowed in return type position for functions and methods. +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. return true; }; @@ -182,19 +182,19 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(133,39 class D { constructor(p1: A): p1 is C { ~~~~~~~ -!!! error TS1228: Type predicate are only allowed in return type position for functions and methods. +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. return true; ~~~~ !!! error TS2409: Return type of constructor signature must be assignable to the instance type of the class } get m1(p1: A): p1 is C { ~~~~~~~ -!!! error TS1228: Type predicate are only allowed in return type position for functions and methods. +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. return true; } set m2(p1: A): p1 is C { ~~~~~~~ -!!! error TS1228: Type predicate are only allowed in return type position for functions and methods. +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. return true; ~~~~ !!! error TS2408: Setters cannot return a value. @@ -204,37 +204,37 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(133,39 interface I1 { new (p1: A): p1 is C; ~~~~~~~ -!!! error TS1228: Type predicate are only allowed in return type position for functions and methods. +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. } interface I2 { [index: number]: p1 is C; ~~~~~~~ -!!! error TS1228: Type predicate are only allowed in return type position for functions and methods. +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. } // Reference to rest parameter function b4(...a): a is A { ~ -!!! error TS1229: Type predicate cannot reference a rest parameter. +!!! error TS1229: A type predicate cannot reference a rest parameter. return true; } // Reference to binding pattern function b5({a, b, p1}, p2, p3): p1 is A { ~~ -!!! error TS1230: Type predicate cannot reference element 'p1' in a binding pattern. +!!! error TS1230: A type predicate cannot reference element 'p1' in a binding pattern. return true; } function b6([a, b, p1], p2, p3): p1 is A { ~~ -!!! error TS1230: Type predicate cannot reference element 'p1' in a binding pattern. +!!! error TS1230: A type predicate cannot reference element 'p1' in a binding pattern. return true; } function b7({a, b, c: {p1}}, p2, p3): p1 is A { ~~ -!!! error TS1230: Type predicate cannot reference element 'p1' in a binding pattern. +!!! error TS1230: A type predicate cannot reference element 'p1' in a binding pattern. return true; } \ No newline at end of file