Skip to content

Suggestion: Classic syntax for function overloading with name mangling through compiler tsconfig flag. #19648

Closed
@jbursey

Description

@jbursey

Feature Request: Compiler Option to allow function overloading in a classic sense.

Code

export class MyOtherClass
{

}

export class Foo()
{
   constructor()
   {
   }

   public Bar() : void
   {
   }

   //-- this syntax would be allowed with a compiler option in .tsconfig "allowNameMangling: true"
   public Bar(num : number) : void
   {
   }
   
   //-- this syntax would be allowed with a compiler option in .tsconfig "allowNameMangling: true"
   public Bar(num : number, data : string ) : void
   {
   }

   //-- this syntax would be allowed with a compiler option in .tsconfig "allowNameMangling: true"
   public Bar(data : string) : void
   {
   }
 
    //-- this syntax would be allowed with a compiler option in .tsconfig "allowNameMangling: true"
   public Bar(obj : MyOtherClass) : void
   {
   }
}

Expected behavior:
Javascript could then be transpilied like so...

var Foo (function()
{
     function Foo() {
     }

     function Bar() {
     }

     function Bar_num_number(num){
     }
   
     function Bar_data_string(data) {
     }

     function Bar_num_number_data_string(num, data) {
     }
 
     function Bar_obj_myotherclass(obj) {
     }
})();

The idea is that from a developer standpoint I might not care what the javascript function name becomes and the typescript compiler could mangle these names and replace all calls to this particular signature with the mangled name in javascript. This would allow me as a developer to better write typescript code and still adhere to javascript requirements with 1 function only per name.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions