Typescript: No auto implementation refactorings for abstract class with method with explicit this parameter.

Created on 6 Jul 2020  路  1Comment  路  Source: microsoft/TypeScript

TypeScript Version: 4.0.0-dev.20200706

Search Terms: refactoring, abstract class, this, suggestions, intellisense,

Code

abstract class Thing {
  abstract run(): void;
}

class ThingImpl extends Thing {
}

abstract class ThingWithThis {
  abstract run(this: ThingWithThis): void;
}

class ThingWithThisImpl extends ThingWithThis {
}

Expected behavior:
Refactorings to auto implement ThingWithThisImpl as such:

abstract class Thing {
  abstract run(): void;
}

class ThingImpl extends Thing {
  run(): void {
    throw new Error("Method not implemented.");
  }
}

abstract class ThingWithThis {
  abstract run(this: ThingWithThis): void;
}

class ThingWithThisImpl extends ThingWithThis {
  run(this: ThingWithThis): void {
    throw new Error("Method not implemented.");
  }
}

Actual behavior:
Implementing the abstract class is not suggested for ThingWithThis.

image
image

Github doesn't support mp4s, so attached is a zip containing an mp4 of the problem if necessary.
problem.zip

Playground Link: Playground Link

Related Issues: N/A?

Bug Quick Fixes Fixed

Most helpful comment

Thanks to both @andrewbranch who fixed this without necessarily knowing it, and @a-tarasyuk for the test (and the other fix)!

>All comments

Thanks to both @andrewbranch who fixed this without necessarily knowing it, and @a-tarasyuk for the test (and the other fix)!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CyrusNajmabadi picture CyrusNajmabadi  路  3Comments

bgrieder picture bgrieder  路  3Comments

DanielRosenwasser picture DanielRosenwasser  路  3Comments

uber5001 picture uber5001  路  3Comments

MartynasZilinskas picture MartynasZilinskas  路  3Comments