Skip to content
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

Missing properties quickfix does not add missing imports #49001

Closed
hpx7 opened this issue May 6, 2022 · 0 comments · Fixed by #49009
Closed

Missing properties quickfix does not add missing imports #49001

hpx7 opened this issue May 6, 2022 · 0 comments · Fixed by #49009
Assignees
Labels
Bug A bug in TypeScript Domain: Quick Fixes Editor-provided fixes, often called code actions. Effort: Casual Good issue if you're already used to contributing to the codebase. Harder than "good first issue". Fix Available A PR has been opened for this issue Help Wanted You can do this

Comments

@hpx7
Copy link

hpx7 commented May 6, 2022

Bug Report

🔎 Search Terms

quickfix missing properties imports

🕗 Version & Regression Information

The quickfix was added in #44576 (cc @a-tarasyuk @komyg) but it doesn't appear to add missing imports.

💻 Code

// foo.ts
import { Bar } from "./bar";

const bar: Bar = {};

// bar.ts
export type SomeType = { x: string };

export interface Bar {
  bar(): SomeType;
}

🙁 Actual behavior

The "Add missing properties" quickfix generates the following:

import { Bar } from "./bar";

const bar: Bar = {
  bar: function (): SomeType { // <-- Cannot find name 'SomeType'
    throw new Error("Function not implemented.");
  }
};

🙂 Expected behavior

import { Bar, SomeType } from "./bar"; // <-- SomeType should be imported

const bar: Bar = {
  bar: function (): SomeType {
    throw new Error("Function not implemented.");
  }
};

Note that this works correctly for classes:

Before quickfix:

import { Bar } from "./bar";

class BarClass implements Bar {};

After "Implement interface Bar" quickfix:

import { Bar, SomeType } from "./bar"; // <-- correctly added

class BarClass implements Bar {
  bar(): SomeType {
    throw new Error("Method not implemented.");
  }
};
@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Help Wanted You can do this Domain: Quick Fixes Editor-provided fixes, often called code actions. Effort: Casual Good issue if you're already used to contributing to the codebase. Harder than "good first issue". labels May 6, 2022
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 4.8.0 milestone May 6, 2022
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label May 7, 2022
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: Quick Fixes Editor-provided fixes, often called code actions. Effort: Casual Good issue if you're already used to contributing to the codebase. Harder than "good first issue". Fix Available A PR has been opened for this issue Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants