microsoft / microsoft/TypeScript
Implementation signatures that do not contain all overloaded signatures are allowed in class definitions
Nobody has claimed this yet.
- 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
💻 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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