Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

'declare method' quick fix adds inline import #37781

Copy link
Copy link
@mjbvz

Description

@mjbvz
Issue body actions

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:

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

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

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.