microsoft / microsoft/TypeScript

Implementation signatures that do not contain all overloaded signatures are allowed in class definitions

Open
#55,963 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: classes
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

🔎 Search Terms

implementation contain overloaded class member

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about overloading class member functions
⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.2.2#code/FAYwNghgzlAEDCwDexZtgMwPZYBSwgH5YAuWAOwFcBbAIwFMAnWASlNgDcsBLAEwG5U6bHgLsqdJgBpYtcTQbM2ZLn0HpMOfBHmTGM2sTITFrdqt5C0KDRpBZyULGHoA6MFgDm+AC4BPAAd6LAwxFn5YAHpI2H8gkLFuOBMmK1gAX2BM4HJ6AHcEXBZXESKIqJiAxm5yHzgAIkpyXnoMGvpeeuAgA

💻 Code
class C
{
    foo( a? : number ) : void;
    foo( a : number, b : number ) : void;
    foo( a : number, b? : number ) : void
    {
        console.log( typeof a ); // typeof a is number
    }
}

new C().foo();  // prints "undefined"
🙁 Actual behavior

The compilation succeeded.

The type of argument "a" in function foo is number but prints "undefined" which is wrong.

Because the implementation signature of foo does not include all overload signatures, so compilation should fail.

🙂 Expected behavior

The compilation should fail.

Additional information about the issue

This bug is only reproduced with class member functions.

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 reproduction and confirm that the class-member overloads compile despite the implementation signature omitting the no-argument case. Trace the class member overload-checking path, add a regression test for this example, and verify that compilation now fails as expected.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.