Skip to content

'declare method' quick fix adds inline import #37781

@mjbvz

Description

@mjbvz

From microsoft/vscode#94118

TypeScript Version: 3.9.0-dev.20200330

Search terms

  • quick fix
  • declare method
  • import

Repro
For a project:

foo.ts

export interface Foo {
    abc: number;
}

export function doFoo(callback: (x: Foo) => void) { }

index.ts

import { doFoo } from "./foo";

class Bar {
    bar() {
        doFoo(x => this.baz(x))
    }
}
  1. Trigger the declare method quick fix on baz

Expected behavior:
An import for Foo is added to the top of the file:

import { doFoo, Foo } from "./foo";

class Bar {
    bar() {
        doFoo(x => this.baz(x))
    }
    baz(x: Foo): void {
        throw new Error("Method not implemented.");
    }
}

Actual behavior:
An inline import is added:

import { doFoo } from "./foo";

class Bar {
    bar() {
        doFoo(x => this.baz(x))
    }
    baz(x: import("./foo").Foo): void {
        throw new Error("Method not implemented.");
    }
}

Playground Link:

Related Issues:

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: LS: Auto-importDomain: LS: Quick FixesEditor-provided fixes, often called code actions.Effort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".FixedA PR has been merged for this issueHelp WantedYou can do this

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions