Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jbursey opened this issue Nov 1, 2017 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@jbursey
Copy link

jbursey commented Nov 1, 2017

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.

@ghost
Copy link

ghost commented Nov 1, 2017

Looks like a duplicate of #12041.
This falls out of scope of our design goals since it would mean type-directed emit.

@ghost ghost added Duplicate An existing issue was already created Out of Scope This idea sits outside of the TypeScript language design constraints labels Nov 1, 2017
@mhegazy mhegazy removed the Out of Scope This idea sits outside of the TypeScript language design constraints label Nov 1, 2017
@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants