microsoft / microsoft/TypeScript

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

Open
#44,181 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

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];
};

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked TypeScript Playground example and compare the declared abstract method with the runtime prototype behavior. Trace how the type of an abstract class's prototype is formed, then verify that concrete methods remain available while abstract methods do not; the issue is done when the reported example type-checks consistently with runtime reality and relevant regression coverage passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.