Skip to content

Commit ebe755b

Browse files
committed
Addresses CR feedback
1 parent 51a43dd commit ebe755b

File tree

4 files changed

+40
-40
lines changed

4 files changed

+40
-40
lines changed

src/compiler/checker.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8588,7 +8588,6 @@ module ts {
85888588
}
85898589

85908590
function getTypePredicateParameterIndex(parameterList: NodeArray<ParameterDeclaration>, parameter: Identifier): number {
8591-
let index = -1;
85928591
if (parameterList) {
85938592
for (let i = 0; i < parameterList.length; i++) {
85948593
let param = parameterList[i];
@@ -8599,6 +8598,7 @@ module ts {
85998598
}
86008599
}
86018600
}
8601+
return -1;
86028602
}
86038603

86048604
function isInLegalTypePredicatePosition(node: Node): boolean {
@@ -8639,7 +8639,7 @@ module ts {
86398639
if (typePredicate.parameterIndex >= 0) {
86408640
if (node.parameters[typePredicate.parameterIndex].dotDotDotToken) {
86418641
error(typePredicateNode.parameterName,
8642-
Diagnostics.Type_predicate_cannot_reference_a_rest_parameter);
8642+
Diagnostics.A_type_predicate_cannot_reference_a_rest_parameter);
86438643
}
86448644
else {
86458645
checkTypeAssignableTo(typePredicate.type,
@@ -8656,24 +8656,24 @@ module ts {
86568656
if (param.name.kind === SyntaxKind.ObjectBindingPattern ||
86578657
param.name.kind === SyntaxKind.ArrayBindingPattern) {
86588658

8659-
(function checkBindingPattern(elements: NodeArray<BindingElement>) {
8660-
for (let element of elements) {
8659+
(function checkBindingPattern(pattern: BindingPattern) {
8660+
for (let element of pattern.elements) {
86618661
if (element.name.kind === SyntaxKind.Identifier &&
86628662
(<Identifier>element.name).text === typePredicate.parameterName) {
86638663

86648664
error(typePredicateNode.parameterName,
8665-
Diagnostics.Type_predicate_cannot_reference_element_0_in_a_binding_pattern,
8665+
Diagnostics.A_type_predicate_cannot_reference_element_0_in_a_binding_pattern,
86668666
typePredicate.parameterName);
86678667
hasReportedError = true;
86688668
break;
86698669
}
8670-
else if(element.name.kind === SyntaxKind.ArrayBindingPattern ||
8670+
else if (element.name.kind === SyntaxKind.ArrayBindingPattern ||
86718671
element.name.kind === SyntaxKind.ObjectBindingPattern) {
86728672

8673-
checkBindingPattern((<BindingPattern>element.name).elements);
8673+
checkBindingPattern(<BindingPattern>element.name);
86748674
}
86758675
}
8676-
})((<BindingPattern>param.name).elements);
8676+
})(<BindingPattern>param.name);
86778677
}
86788678
}
86798679
if (!hasReportedError) {
@@ -8685,7 +8685,7 @@ module ts {
86858685
}
86868686
else {
86878687
error(typePredicateNode,
8688-
Diagnostics.Type_predicate_are_only_allowed_in_return_type_position_for_functions_and_methods);
8688+
Diagnostics.A_type_predicate_is_only_allowed_in_return_type_position_for_functions_and_methods);
86898689
}
86908690
}
86918691
else {
@@ -11327,7 +11327,7 @@ module ts {
1132711327

1132811328
function checkTypePredicate(node: TypePredicateNode) {
1132911329
if(!isInLegalTypePredicatePosition(node)) {
11330-
error(node, Diagnostics.Type_predicate_are_only_allowed_in_return_type_position_for_functions_and_methods);
11330+
error(node, Diagnostics.A_type_predicate_is_only_allowed_in_return_type_position_for_functions_and_methods);
1133111331
}
1133211332
}
1133311333

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ module ts {
183183
Cannot_find_parameter_0: { code: 1225, category: DiagnosticCategory.Error, key: "Cannot find parameter '{0}'." },
184184
Type_predicate_0_is_not_assignable_to_1: { code: 1226, category: DiagnosticCategory.Error, key: "Type predicate '{0}' is not assignable to '{1}'." },
185185
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}'." },
186-
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." },
187-
Type_predicate_cannot_reference_a_rest_parameter: { code: 1229, category: DiagnosticCategory.Error, key: "Type predicate cannot reference a rest parameter." },
188-
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." },
186+
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." },
187+
A_type_predicate_cannot_reference_a_rest_parameter: { code: 1229, category: DiagnosticCategory.Error, key: "A type predicate cannot reference a rest parameter." },
188+
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." },
189189
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
190190
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." },
191191
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },

src/compiler/diagnosticMessages.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -719,15 +719,15 @@
719719
"category": "Error",
720720
"code": 1227
721721
},
722-
"Type predicate are only allowed in return type position for functions and methods.": {
722+
"A type predicate is only allowed in return type position for functions and methods.": {
723723
"category": "Error",
724724
"code": 1228
725725
},
726-
"Type predicate cannot reference a rest parameter.": {
726+
"A type predicate cannot reference a rest parameter.": {
727727
"category": "Error",
728728
"code": 1229
729729
},
730-
"Type predicate cannot reference element '{0}' in a binding pattern.": {
730+
"A type predicate cannot reference element '{0}' in a binding pattern.": {
731731
"category": "Error",
732732
"code": 1230
733733
},

tests/baselines/reference/typeGuardFunctionErrors.errors.txt

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(81,1):
2020
Type predicate 'p2 is A' is not assignable to 'p1 is A'.
2121
Parameter 'p2' is not in the same position as parameter 'p1'.
2222
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'.
23-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(92,9): error TS1228: Type predicate are only allowed in return type position for functions and methods.
24-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(93,16): error TS1228: Type predicate are only allowed in return type position for functions and methods.
25-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(94,20): error TS1228: Type predicate are only allowed in return type position for functions and methods.
26-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(100,25): error TS1228: Type predicate are only allowed in return type position for functions and methods.
23+
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.
24+
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.
25+
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.
26+
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.
2727
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
28-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(103,20): error TS1228: Type predicate are only allowed in return type position for functions and methods.
29-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(106,20): error TS1228: Type predicate are only allowed in return type position for functions and methods.
28+
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.
29+
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.
3030
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(107,16): error TS2408: Setters cannot return a value.
31-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(112,18): error TS1228: Type predicate are only allowed in return type position for functions and methods.
32-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(116,22): error TS1228: Type predicate are only allowed in return type position for functions and methods.
33-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(120,20): error TS1229: Type predicate cannot reference a rest parameter.
34-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(125,34): error TS1230: Type predicate cannot reference element 'p1' in a binding pattern.
35-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(129,34): error TS1230: Type predicate cannot reference element 'p1' in a binding pattern.
36-
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(133,39): error TS1230: Type predicate cannot reference element 'p1' in a binding pattern.
31+
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.
32+
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.
33+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(120,20): error TS1229: A type predicate cannot reference a rest parameter.
34+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(125,34): error TS1230: A type predicate cannot reference element 'p1' in a binding pattern.
35+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(129,34): error TS1230: A type predicate cannot reference element 'p1' in a binding pattern.
36+
tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(133,39): error TS1230: A type predicate cannot reference element 'p1' in a binding pattern.
3737

3838

3939
==== tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts (30 errors) ====
@@ -168,33 +168,33 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(133,39
168168
// Type predicates in non-return type positions
169169
var b1: b is A;
170170
~~~~~~
171-
!!! error TS1228: Type predicate are only allowed in return type position for functions and methods.
171+
!!! error TS1228: A type predicate is only allowed in return type position for functions and methods.
172172
function b2(a: b is A) {};
173173
~~~~~~
174-
!!! error TS1228: Type predicate are only allowed in return type position for functions and methods.
174+
!!! error TS1228: A type predicate is only allowed in return type position for functions and methods.
175175
function b3(): A | b is A {
176176
~~~~~~
177-
!!! error TS1228: Type predicate are only allowed in return type position for functions and methods.
177+
!!! error TS1228: A type predicate is only allowed in return type position for functions and methods.
178178
return true;
179179
};
180180

181181
// Non-compatiable type predicate positions for signature declarations
182182
class D {
183183
constructor(p1: A): p1 is C {
184184
~~~~~~~
185-
!!! error TS1228: Type predicate are only allowed in return type position for functions and methods.
185+
!!! error TS1228: A type predicate is only allowed in return type position for functions and methods.
186186
return true;
187187
~~~~
188188
!!! error TS2409: Return type of constructor signature must be assignable to the instance type of the class
189189
}
190190
get m1(p1: A): p1 is C {
191191
~~~~~~~
192-
!!! error TS1228: Type predicate are only allowed in return type position for functions and methods.
192+
!!! error TS1228: A type predicate is only allowed in return type position for functions and methods.
193193
return true;
194194
}
195195
set m2(p1: A): p1 is C {
196196
~~~~~~~
197-
!!! error TS1228: Type predicate are only allowed in return type position for functions and methods.
197+
!!! error TS1228: A type predicate is only allowed in return type position for functions and methods.
198198
return true;
199199
~~~~
200200
!!! error TS2408: Setters cannot return a value.
@@ -204,37 +204,37 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(133,39
204204
interface I1 {
205205
new (p1: A): p1 is C;
206206
~~~~~~~
207-
!!! error TS1228: Type predicate are only allowed in return type position for functions and methods.
207+
!!! error TS1228: A type predicate is only allowed in return type position for functions and methods.
208208
}
209209

210210
interface I2 {
211211
[index: number]: p1 is C;
212212
~~~~~~~
213-
!!! error TS1228: Type predicate are only allowed in return type position for functions and methods.
213+
!!! error TS1228: A type predicate is only allowed in return type position for functions and methods.
214214
}
215215

216216
// Reference to rest parameter
217217
function b4(...a): a is A {
218218
~
219-
!!! error TS1229: Type predicate cannot reference a rest parameter.
219+
!!! error TS1229: A type predicate cannot reference a rest parameter.
220220
return true;
221221
}
222222

223223
// Reference to binding pattern
224224
function b5({a, b, p1}, p2, p3): p1 is A {
225225
~~
226-
!!! error TS1230: Type predicate cannot reference element 'p1' in a binding pattern.
226+
!!! error TS1230: A type predicate cannot reference element 'p1' in a binding pattern.
227227
return true;
228228
}
229229

230230
function b6([a, b, p1], p2, p3): p1 is A {
231231
~~
232-
!!! error TS1230: Type predicate cannot reference element 'p1' in a binding pattern.
232+
!!! error TS1230: A type predicate cannot reference element 'p1' in a binding pattern.
233233
return true;
234234
}
235235

236236
function b7({a, b, c: {p1}}, p2, p3): p1 is A {
237237
~~
238-
!!! error TS1230: Type predicate cannot reference element 'p1' in a binding pattern.
238+
!!! error TS1230: A type predicate cannot reference element 'p1' in a binding pattern.
239239
return true;
240240
}

0 commit comments

Comments
 (0)