Skip to content

Commit c043944

Browse files
Let isolated declarations fixer add toplevel imports more (#60267)
1 parent 79ea5a5 commit c043944

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

src/services/codefixes/helpers.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -606,12 +606,10 @@ export function typeToAutoImportableTypeNode(checker: TypeChecker, importAdder:
606606

607607
/** @internal */
608608
export function typeNodeToAutoImportableTypeNode(typeNode: TypeNode, importAdder: ImportAdder, scriptTarget: ScriptTarget): TypeNode | undefined {
609-
if (typeNode && isImportTypeNode(typeNode)) {
610-
const importableReference = tryGetAutoImportableReferenceFromTypeNode(typeNode, scriptTarget);
611-
if (importableReference) {
612-
importSymbols(importAdder, importableReference.symbols);
613-
typeNode = importableReference.typeNode;
614-
}
609+
const importableReference = tryGetAutoImportableReferenceFromTypeNode(typeNode, scriptTarget);
610+
if (importableReference) {
611+
importSymbols(importAdder, importableReference.symbols);
612+
typeNode = importableReference.typeNode;
615613
}
616614

617615
// Ensure nodes are fresh so they can have different positions when going through formatting.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
// @isolatedDeclarations: true
4+
// @declaration: true
5+
6+
// @Filename: /person-code.ts
7+
////export interface Person { x: string; }
8+
////export function getPerson() : Person {
9+
//// return null!
10+
////}
11+
12+
// @Filename: /code.ts
13+
////import { getPerson } from "./person-code";
14+
////export function wrapPerson() {
15+
//// return { person: getPerson() }
16+
////};
17+
18+
goTo.file("/code.ts");
19+
20+
verify.codeFix({
21+
description: "Add return type '{ person: Person; }'",
22+
index: 0,
23+
newFileContent:
24+
`import { getPerson, Person } from "./person-code";
25+
export function wrapPerson(): {
26+
person: Person;
27+
} {
28+
return { person: getPerson() }
29+
};`
30+
});

0 commit comments

Comments
 (0)