Skip to content

Commit c44fd46

Browse files
authored
fix(47451): Implicit 'any' quick fix text grabs text from wrong file (microsoft#47493)
1 parent 97017ee commit c44fd46

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/services/codefixes/inferFromUsage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ namespace ts.codefix {
5858
});
5959
const name = declaration && getNameOfDeclaration(declaration);
6060
return !name || changes.length === 0 ? undefined
61-
: [createCodeFixAction(fixId, changes, [getDiagnostic(errorCode, token), name.getText(sourceFile)], fixId, Diagnostics.Infer_all_types_from_usage)];
61+
: [createCodeFixAction(fixId, changes, [getDiagnostic(errorCode, token), getTextOfNode(name)], fixId, Diagnostics.Infer_all_types_from_usage)];
6262
},
6363
fixIds: [fixId],
6464
getAllCodeActions(context) {
@@ -141,7 +141,7 @@ namespace ts.codefix {
141141
case Diagnostics.Variable_0_implicitly_has_an_1_type.code: {
142142
const symbol = program.getTypeChecker().getSymbolAtLocation(token);
143143
if (symbol && symbol.valueDeclaration && isVariableDeclaration(symbol.valueDeclaration) && markSeen(symbol.valueDeclaration)) {
144-
annotateVariableDeclaration(changes, importAdder, sourceFile, symbol.valueDeclaration, program, host, cancellationToken);
144+
annotateVariableDeclaration(changes, importAdder, getSourceFileOfNode(symbol.valueDeclaration), symbol.valueDeclaration, program, host, cancellationToken);
145145
importAdder.writeFixes(changes);
146146
return symbol.valueDeclaration;
147147
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @noImplicitAny: true
4+
5+
// @Filename: /a.ts
6+
////var foobarfoobarfoobarfoobar;
7+
8+
// @Filename: /b.ts
9+
////function bar() {
10+
//// let y = foobarfoobarfoobarfoobar/**/;
11+
////}
12+
13+
goTo.file("/b.ts");
14+
goTo.marker("");
15+
verify.codeFix({
16+
description: "Infer type of 'foobarfoobarfoobarfoobar' from usage",
17+
index: 0,
18+
newFileContent: {
19+
"/a.ts": "var foobarfoobarfoobarfoobar: any;"
20+
}
21+
});

0 commit comments

Comments
 (0)