mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Try to provide a spelling suggestion when object literals have excess properties.
This commit is contained in:
+18
-3
@@ -9067,11 +9067,26 @@ namespace ts {
|
||||
else {
|
||||
// use the property's value declaration if the property is assigned inside the literal itself
|
||||
const objectLiteralDeclaration = source.symbol && firstOrUndefined(source.symbol.declarations);
|
||||
let suggestion;
|
||||
if (prop.valueDeclaration && findAncestor(prop.valueDeclaration, d => d === objectLiteralDeclaration)) {
|
||||
errorNode = prop.valueDeclaration;
|
||||
const propDeclaration = prop.valueDeclaration as ObjectLiteralElementLike;
|
||||
Debug.assertNode(propDeclaration, isObjectLiteralElementLike);
|
||||
|
||||
errorNode = propDeclaration;
|
||||
|
||||
const propNameNode = propDeclaration.name as Identifier;
|
||||
Debug.assertNode(propNameNode, isIdentifier);
|
||||
suggestion = getSuggestionForNonexistentProperty(propNameNode, target);
|
||||
}
|
||||
|
||||
if (suggestion !== undefined) {
|
||||
reportError(Diagnostics.Object_literal_may_only_specify_known_properties_but_0_does_not_exist_in_type_1_Did_you_mean_to_write_2,
|
||||
symbolToString(prop), typeToString(target), unescapeLeadingUnderscores(suggestion));
|
||||
}
|
||||
else {
|
||||
reportError(Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1,
|
||||
symbolToString(prop), typeToString(target));
|
||||
}
|
||||
reportError(Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1,
|
||||
symbolToString(prop), typeToString(target));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -1912,6 +1912,10 @@
|
||||
"category": "Error",
|
||||
"code": 2560
|
||||
},
|
||||
"Object literal may only specify known properties, but '{0}' does not exist in type '{1}'. Did you mean to write '{2}'?": {
|
||||
"category": "Error",
|
||||
"code": 2561
|
||||
},
|
||||
"JSX element attributes type '{0}' may not be a union type.": {
|
||||
"category": "Error",
|
||||
"code": 2600
|
||||
|
||||
Reference in New Issue
Block a user