Error on for (const x in never) (#22988)

* Error on `for (const x in never)`

* Update diagnostic

* Provide argument to diagnostic
This commit is contained in:
Andy
2018-03-29 11:39:30 -07:00
committed by GitHub
parent 6c517ef276
commit a9aca81601
17 changed files with 69 additions and 37 deletions

View File

@@ -22590,8 +22590,8 @@ namespace ts {
// unknownType is returned i.e. if node.expression is identifier whose name cannot be resolved
// in this case error about missing name is already reported - do not report extra one
if (!isTypeAssignableToKind(rightType, TypeFlags.NonPrimitive | TypeFlags.InstantiableNonPrimitive)) {
error(node.expression, Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter);
if (rightType === neverType || !isTypeAssignableToKind(rightType, TypeFlags.NonPrimitive | TypeFlags.InstantiableNonPrimitive)) {
error(node.expression, Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter_but_here_has_type_0, typeToString(rightType));
}
checkSourceElement(node.statement);

View File

@@ -1372,7 +1372,7 @@
"category": "Error",
"code": 2406
},
"The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter.": {
"The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type '{0}'.": {
"category": "Error",
"code": 2407
},