Skip to content

Missing properties quickfix does not add missing imports #49001

Closed
@hpx7

Description

@hpx7

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.");
  }
};

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: Quick FixesEditor-provided fixes, often called code actions.Effort: CasualGood issue if you're already used to contributing to the codebase. Harder than "good first issue".Fix AvailableA PR has been opened for this issueHelp WantedYou can do this

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions