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

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

Closed
Tyriar opened this issue Nov 8, 2017 · 14 comments
Labels
Bug A bug in TypeScript Domain: Quick Fixes Editor-provided fixes, often called code actions. Good First Issue Well scoped, documented and has the green light Help Wanted You can do this
Milestone

Comments

@Tyriar
Copy link
Member

Tyriar commented Nov 8, 2017

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

}
@mhegazy mhegazy added Bug A bug in TypeScript Domain: Quick Fixes Editor-provided fixes, often called code actions. labels Nov 8, 2017
@mhegazy mhegazy added this to the TypeScript 2.7 milestone Nov 8, 2017
@mhegazy mhegazy added Help Wanted You can do this Good First Issue Well scoped, documented and has the green light labels Nov 8, 2017
@mhegazy mhegazy modified the milestones: TypeScript 2.7, Community Nov 8, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Nov 8, 2017

PRs welcomed...

@MhdTlb
Copy link

MhdTlb commented Nov 9, 2017

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

@mhegazy
Copy link
Contributor

mhegazy commented Nov 9, 2017

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));

@shobhitchittora
Copy link

@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.

@mhegazy
Copy link
Contributor

mhegazy commented Nov 10, 2017

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.

@mhegazy
Copy link
Contributor

mhegazy commented Nov 10, 2017

@shobhitchittora
Copy link

@mhegazy @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.

@Tyriar
Copy link
Member Author

Tyriar commented Nov 11, 2017

@mjbvz might be able to help with debugging in vscode

@shobhitchittora
Copy link

Ping @mjbvz. Can you help with this?

@mjbvz
Copy link
Contributor

mjbvz commented Dec 19, 2017

@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
}

@shobhitchittora
Copy link

A few updates on this thread -

  1. @mjbvz Thanks. It really helped.
  2. The TypeScript/src/services/codefixes/helpers.ts is refactored since the last comment by @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 @mhegazy behaves the same.

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

@dragomirtitian
Copy link
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 :) )

@RyanCavanaugh RyanCavanaugh modified the milestones: Community, Backlog Mar 7, 2019
@mjbvz
Copy link
Contributor

mjbvz commented Jan 29, 2020

Confirmed that this is fixed with TS 3.7.5

@mjbvz mjbvz closed this as completed Jan 29, 2020
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. Good First Issue Well scoped, documented and has the green light Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

8 participants