Destructuring of tuple type cannot specify extra variables

This commit is contained in:
Anders Hejlsberg 2014-11-20 13:45:55 -08:00
parent 850f3cb609
commit 2ed5f418a1
3 changed files with 26 additions and 7 deletions

View file

@ -1644,10 +1644,18 @@ module ts {
}
}
else {
var index = indexOf(pattern.elements, declaration);
var type = getTypeOfPropertyOfType(parentType, "" + index) || getIndexTypeOfType(parentType, IndexKind.Number);
if (!type) {
error(declaration, Diagnostics.Type_0_has_no_property_1_and_no_numeric_index_signature, typeToString(parentType), "" + index);
if (getPropertyOfType(parentType, "0")) {
var propName = "" + indexOf(pattern.elements, declaration);
var type = getTypeOfPropertyOfType(parentType, propName);
if (!type) {
error(declaration, Diagnostics.Type_0_has_no_property_1, typeToString(parentType), propName);
}
}
else {
var type = getIndexTypeOfType(parentType, IndexKind.Number);
if (!type) {
error(declaration, Diagnostics.Type_0_has_no_numeric_index_signature, typeToString(parentType));
}
}
}
return type || unknownType;
@ -4775,7 +4783,13 @@ module ts {
return getTypeFromTypeNode(declaration.type);
}
if (declaration.kind === SyntaxKind.Parameter) {
return getContextuallyTypedParameterType(declaration);
var type = getContextuallyTypedParameterType(declaration);
if (type) {
return type;
}
}
if (isBindingPattern(declaration.name)) {
return getTypeFromBindingPattern(<BindingPattern>declaration.name);
}
}
return undefined;

View file

@ -275,7 +275,8 @@ module ts {
Type_alias_0_circularly_references_itself: { code: 2456, category: DiagnosticCategory.Error, key: "Type alias '{0}' circularly references itself." },
Type_alias_name_cannot_be_0: { code: 2457, category: DiagnosticCategory.Error, key: "Type alias name cannot be '{0}'" },
Type_0_has_no_property_1_and_no_string_index_signature: { code: 2458, category: DiagnosticCategory.Error, key: "Type '{0}' has no property '{1}' and no string index signature." },
Type_0_has_no_property_1_and_no_numeric_index_signature: { code: 2459, category: DiagnosticCategory.Error, key: "Type '{0}' has no property '{1}' and no numeric index signature." },
Type_0_has_no_property_1: { code: 2459, category: DiagnosticCategory.Error, key: "Type '{0}' has no property '{1}'." },
Type_0_has_no_numeric_index_signature: { code: 2460, category: DiagnosticCategory.Error, key: "Type '{0}' has no numeric index signature." },
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4001, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'." },
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },

View file

@ -1096,10 +1096,14 @@
"category": "Error",
"code": 2458
},
"Type '{0}' has no property '{1}' and no numeric index signature.": {
"Type '{0}' has no property '{1}'.": {
"category": "Error",
"code": 2459
},
"Type '{0}' has no numeric index signature.": {
"category": "Error",
"code": 2460
},
"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",