Skip to content

abstract class prototype type has abstract methods even though they are not on the prototypeΒ #44181

@Pmyl

Description

@Pmyl

Bug Report

πŸ”Ž Search Terms

abstract, prototype, type

πŸ•— Version & Regression Information

All versions I tried

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

abstract class AnAbstract {
  public abstract abstractMethod(): void;

  public nonAbstractMethod(): void {
    // do something
  }
}

// no type error - undefined
console.log(AnAbstract.prototype.abstractMethod);
// no type error - false
console.log(AnAbstract.prototype.hasOwnProperty('abstractMethod'));

// defined
console.log(AnAbstract.prototype.nonAbstractMethod);
// true
console.log(AnAbstract.prototype.hasOwnProperty('nonAbstractMethod'));

πŸ™ Actual behavior

Abstract class prototype has abstract methods in the type

πŸ™‚ Expected behavior

Abstract class prototype to have only concrete methods in the type


I have a function that manually define methods based on what's in the prototype, unfortunately when I use an abstract class the type doesn't reflect reality.

If that type cannot change it would be great to be able to do something like:

type NoAbstract<T> = {
  -abstract [key in keyof T]: T[key];
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions