Skip to content

'declare method' quick fix adds inline import #37781

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mjbvz opened this issue Apr 3, 2020 · 1 comment · Fixed by #37857
Closed

'declare method' quick fix adds inline import #37781

mjbvz opened this issue Apr 3, 2020 · 1 comment · Fixed by #37857
Assignees
Labels
Bug A bug in TypeScript Domain: Auto-import Domain: Quick Fixes Editor-provided fixes, often called code actions. Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Fixed A PR has been merged for this issue Help Wanted You can do this

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Apr 3, 2020

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:

@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Domain: Auto-import Domain: Quick Fixes Editor-provided fixes, often called code actions. labels Apr 3, 2020
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 3.9.1 milestone Apr 3, 2020
@DanielRosenwasser DanielRosenwasser added Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Help Wanted You can do this labels Apr 3, 2020
@DanielRosenwasser DanielRosenwasser added the Fixed A PR has been merged for this issue label Apr 13, 2020
@DanielRosenwasser
Copy link
Member

Thanks @a-tarasyuk!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Auto-import Domain: Quick Fixes Editor-provided fixes, often called code actions. Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Fixed A PR has been merged for this issue Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants