Skip to content

Implement interface helper does not consider what is already implemented on base classes #19847

Closed

Description

@Tyriar

TypeScript Version: 2.6.1 (VS Code Insiders)

Code

interface MyInterface {
  foo(): void;
}

interface IBase extends MyInterface {
  bar(): void;
}

abstract class Base implements MyInterface {
  foo(): void {}
}

class MyClass extends Base implements IBase {

}

When I implement interface IBase, it's not figuring out which methods are already implemented on the base classes.

image

Expected behavior:

class MyClass extends Base implements IBase {
  bar(): void {
    throw new Error("Method not implemented.");
  }
}

Actual behavior:

class MyClass extends Base implements IBase {
  bar(): void {
    throw new Error("Method not implemented.");
  }
  foo(): void {
    throw new Error("Method not implemented.");
  }

}

Activity

  1. modified the milestones: TypeScript 2.7, on Nov 8, 2017
  2. mhegazy commented on Nov 8, 2017

    @mhegazy
    Contributor

    PRs welcomed...

  3. MhdTlb commented on Nov 9, 2017

    @MhdTlb

    I would like to work on this issue but I need some guidance

  4. mhegazy commented on Nov 9, 2017

    @mhegazy
    Contributor

    sure. The code for this fix is in https://github.com/Microsoft/TypeScript/blob/master/src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts

    The fix should probably be in https://github.com/Microsoft/TypeScript/blob/d998e97d8c64acf1ed4b8cd508a4589c110bd3aa/src/services/codefixes/helpers.ts#L36 to change const classMembers = classDeclaration.symbol.members; to const classMembers = checker.getPropertiesOfType(checker.getTypeAtLocation(classDeclaration));

  5. shobhitchittora commented on Nov 10, 2017

    @shobhitchittora

    Mohamed Hegazy (@mhegazy) I've made the required changes and would like to test now. How can I test whether the issue is fixed? Also how to debug ts compiler changes?

    PS: I used vscode to reproduce the issue.

  6. mhegazy commented on Nov 10, 2017

    @mhegazy
    Contributor

    VSCode ships with an older version of TypeScript. Please see Using Newer TypeScript Versions documentation for more details on updating your VSCode to use a different version of TypeScript.

  7. shobhitchittora commented on Nov 11, 2017

    @shobhitchittora

    Mohamed Hegazy (@mhegazy) Daniel Imms (@Tyriar) Need help debugging ts executions from vscode. I tried putting a debugger; in my ts file hoping that it'd stop while fixing incorrectly implemented interfaces in my vscode OSSDEV build, but it does not.

    Thanks in advance.
    PS: I've configured my vscode nightly build (from master) to load local tsserver.js.

  8. Tyriar commented on Nov 11, 2017

    @Tyriar
    ContributorAuthor

    Matt Bierner (@mjbvz) might be able to help with debugging in vscode

  9. shobhitchittora commented on Dec 17, 2017

    @shobhitchittora

    Ping Matt Bierner (@mjbvz). Can you help with this?

  10. mjbvz commented on Dec 19, 2017

    @mjbvz

    Shobhit Chittora (@shobhitchittora) To debug the ts server loaded by code:

    First point your vscode typescript.tsdk user setting your locally build version of TypeScript:

    "typescript.tsdk": "/Users/matb/projects/TypeScript/built/local/"
    

    Using a local build of code, change the execArgv in this file to be execArgv: ['--inspect=5859']

    Attach to the ts server spawned by the local build of code using:

    {
    	"type": "node",
    	"request": "attach",
    	"name": "Attach to TS Server",
    	"protocol": "inspector",
    	"port": 5859
    }
  11. shobhitchittora commented on Dec 20, 2017

    @shobhitchittora

    A few updates on this thread -

    1. Matt Bierner (@mjbvz) Thanks. It really helped.
    2. The TypeScript/src/services/codefixes/helpers.ts is refactored since the last comment by Mohamed Hegazy (@mhegazy). The method new is at - https://github.com/Microsoft/TypeScript/blob/master/src/services/codefixes/helpers.ts#L9.

    Blocker-

    1. classMembers is coming as empty array when try to get autofix suggestion in vscode. ( refer screenshot )
    2. Even the fix suggested by Mohamed Hegazy (@mhegazy) behaves the same.

    screen shot 2017-12-20 at 3 34 12 pm

  12. dragomirtitian commented on Nov 13, 2018

    @dragomirtitian
    Contributor

    This issue should be closed. It no longer happens since 3.0. (Had my eye on fixing it and found I had nothing to fix :) )

  13. mjbvz commented on Jan 29, 2020

    @mjbvz

    Confirmed that this is fixed with TS 3.7.5

  14. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: LS: Quick FixesEditor-provided fixes, often called code actions.Good First IssueWell scoped, documented and has the green lightHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions