Skip to content

Commit

Permalink
Let isolated declarations fixer add toplevel imports more (#60267)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminjkraft authored Nov 13, 2024
1 parent 79ea5a5 commit c043944
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/services/codefixes/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,12 +606,10 @@ export function typeToAutoImportableTypeNode(checker: TypeChecker, importAdder:

/** @internal */
export function typeNodeToAutoImportableTypeNode(typeNode: TypeNode, importAdder: ImportAdder, scriptTarget: ScriptTarget): TypeNode | undefined {
if (typeNode && isImportTypeNode(typeNode)) {
const importableReference = tryGetAutoImportableReferenceFromTypeNode(typeNode, scriptTarget);
if (importableReference) {
importSymbols(importAdder, importableReference.symbols);
typeNode = importableReference.typeNode;
}
const importableReference = tryGetAutoImportableReferenceFromTypeNode(typeNode, scriptTarget);
if (importableReference) {
importSymbols(importAdder, importableReference.symbols);
typeNode = importableReference.typeNode;
}

// Ensure nodes are fresh so they can have different positions when going through formatting.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/// <reference path='fourslash.ts'/>

// @isolatedDeclarations: true
// @declaration: true

// @Filename: /person-code.ts
////export interface Person { x: string; }
////export function getPerson() : Person {
//// return null!
////}

// @Filename: /code.ts
////import { getPerson } from "./person-code";
////export function wrapPerson() {
//// return { person: getPerson() }
////};

goTo.file("/code.ts");

verify.codeFix({
description: "Add return type '{ person: Person; }'",
index: 0,
newFileContent:
`import { getPerson, Person } from "./person-code";
export function wrapPerson(): {
person: Person;
} {
return { person: getPerson() }
};`
});

0 comments on commit c043944

Please sign in to comment.