mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-20 05:17:43 -05:00
Add related span pointing to this-shadowing location for implicitly-any this (#28299)
* Add diagnostic pointing to this-shadowing location * Fix almost-top-level-this case * Change message on span
This commit is contained in:
@@ -16296,11 +16296,17 @@ namespace ts {
|
||||
const type = tryGetThisTypeAt(node, container);
|
||||
if (!type && noImplicitThis) {
|
||||
// With noImplicitThis, functions may not reference 'this' if it has type 'any'
|
||||
error(
|
||||
const diag = error(
|
||||
node,
|
||||
capturedByArrowFunction && container.kind === SyntaxKind.SourceFile ?
|
||||
Diagnostics.The_containing_arrow_function_captures_the_global_value_of_this_which_implicitly_has_type_any :
|
||||
Diagnostics.this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation);
|
||||
if (!isSourceFile(container)) {
|
||||
const outsideThis = tryGetThisTypeAt(container);
|
||||
if (outsideThis) {
|
||||
addRelatedInfo(diag, createDiagnosticForNode(container, Diagnostics.An_outer_value_of_this_is_shadowed_by_this_container));
|
||||
}
|
||||
}
|
||||
}
|
||||
return type || anyType;
|
||||
}
|
||||
|
||||
@@ -2509,6 +2509,10 @@
|
||||
"category": "Error",
|
||||
"code": 2737
|
||||
},
|
||||
"An outer value of 'this' is shadowed by this container.": {
|
||||
"category": "Message",
|
||||
"code": 2738
|
||||
},
|
||||
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
|
||||
Reference in New Issue
Block a user