Skip to content

Implement interface only working after specifying import #45192

@RollingSquirrel

Description

@RollingSquirrel

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.58.2
  • OS Version: Windows_NT x64 10.0.19042

Description

I am developing an express.js application with TypeScript.
The "Implement interface" usually available with shortcut or "Quick Fix" stopped working in my project over time.
This seems very odd to me since I did not change anything in the tsconfig.json during this time.

I have tried to fix the problem with the following:

  • Delete tsconfig completely (and restart after this)
  • Disable all extensions
  • Restart (Pc & VSC)
  • Restart ts server (command in VSC)
  • Reload project (command in VSC)
  • npm ci, manually remove node_modules
  • Restore repo to the last time this option worked (hard reset, restart)

After playing around with the code for a while, I discovered that importing the node_modules dependency used in the type declarations of the interface, makes the implement feature available again.
I have tested other imported types (e.g. typeorm) which seem to work fine without specifying the import.

Steps to Reproduce:

I will provide a simple example that requires the Router type of express.js.
This worked fine a few days ago and stopped working after some time. I attempted to reset everything but it did not change the behavior. Is there any cache / something similar that I should reset / delete?

controller.ts

import { Router } from "express";

export interface Controller {
  getRouter(): Router
}

user-controller.ts

import { Controller } from "./controller";

export class UserController implements Controller {
  // want to use "implement" here
}

Depending on the import the option appears again:
Without import:

image

With import:

image

Let me know if you require more details.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions