{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3442","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3442/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3442/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3442/events","html_url":"https://github.com/Microsoft/TypeScript/issues/3442","id":86619542,"number":3442,"title":"Suggestion: Compile time function overloading","user":{"login":"aleksey-bykov","id":937933,"avatar_url":"https://avatars.githubusercontent.com/u/937933?v=3","gravatar_id":"","url":"https://api.github.com/users/aleksey-bykov","html_url":"https://github.com/aleksey-bykov","followers_url":"https://api.github.com/users/aleksey-bykov/followers","following_url":"https://api.github.com/users/aleksey-bykov/following{/other_user}","gists_url":"https://api.github.com/users/aleksey-bykov/gists{/gist_id}","starred_url":"https://api.github.com/users/aleksey-bykov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aleksey-bykov/subscriptions","organizations_url":"https://api.github.com/users/aleksey-bykov/orgs","repos_url":"https://api.github.com/users/aleksey-bykov/repos","events_url":"https://api.github.com/users/aleksey-bykov/events{/privacy}","received_events_url":"https://api.github.com/users/aleksey-bykov/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Needs%20Proposal","name":"Needs Proposal","color":"556b75"},{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Suggestion","name":"Suggestion","color":"006b75"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":24,"created_at":"2015-06-09T14:31:54Z","updated_at":"2016-02-26T14:35:54Z","closed_at":null,"body":"As we know JavaScript doesn't support overloaded functions, it's when a few functions with different signatures share the same name within the same scope where they are defined. Overloading can still be achieved at runtime by checking arguments and dispatching the execution to a proper path.\r\n\r\nTypeScript seems capable of doing static function overloading which can be resolved at the compile time. Here is one way of how it can be done:\r\n\r\n- a notion of a nominal and effective name of a function is required\r\n- a nominal name is an identifier which is used to name a function and reference it in the TypeScript code\r\n- an effective name is an identifier which is used to name a function and reference it in the JavaScript code\r\n- an effective name is optional, if omitted then the effective name should be the same as the nominal name\r\n- a nominal name is a subject for overloading and hence can be shared across more than one function within the same scope\r\n- an effective name has to be unique withing the scope\r\n- the developer is in charge for specifying both nominal and effective names\r\n- the TypeScript emitter should only use the effective names for generating the JavaScript code\r\n- a resolution of a nominal name to an effective name should be based on the signature information\r\n- the hypothetical syntax (TBD) for a function declaration utilizing both the effective and nominal name might look like the following:\r\n```typescript\r\n\r\nfunction nominalName:effectiveName() : void {\r\n}\r\n\r\n```\r\n\r\nExample:\r\n```typescript\r\n// typescript\r\n\r\nfunction format:formatNumber(value: number) : string {\r\n     return number.toFixed(2);\r\n}\r\n\r\nfunciton format:formatDate(value: Date): string {\r\n    return date.toIsoString();\r\n}\r\n\r\nvar when = format(new Date());\r\nvar howMuch = format(999.99);\r\n```\r\n\r\n```javascript\r\n/// generated javascript\r\n\r\nfunction formatNumber(value: number) : string {\r\n     return number.toFixed(2);\r\n}\r\n\r\nfunciton formatDate(value: Date): string {\r\n    return date.toIsoString();\r\n}\r\n\r\nvar when = formatNumber(new Date());\r\nvar howMuch = formatDate(999.99);\r\n```"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/189306008","html_url":"https://github.com/Microsoft/TypeScript/issues/3442#issuecomment-189306008","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3442","id":189306008,"user":{"login":"SamuelEnglard","id":1119883,"avatar_url":"https://avatars.githubusercontent.com/u/1119883?v=3","gravatar_id":"","url":"https://api.github.com/users/SamuelEnglard","html_url":"https://github.com/SamuelEnglard","followers_url":"https://api.github.com/users/SamuelEnglard/followers","following_url":"https://api.github.com/users/SamuelEnglard/following{/other_user}","gists_url":"https://api.github.com/users/SamuelEnglard/gists{/gist_id}","starred_url":"https://api.github.com/users/SamuelEnglard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SamuelEnglard/subscriptions","organizations_url":"https://api.github.com/users/SamuelEnglard/orgs","repos_url":"https://api.github.com/users/SamuelEnglard/repos","events_url":"https://api.github.com/users/SamuelEnglard/events{/privacy}","received_events_url":"https://api.github.com/users/SamuelEnglard/received_events","type":"User","site_admin":false},"created_at":"2016-02-26T14:35:54Z","updated_at":"2016-02-26T14:35:54Z","body":"I think another point from the Design Goals is the key here:\r\n\r\n> 4. Provide an end-to-end build pipeline. Instead, make the system extensible so that external tools can use the compiler for more complex build workflows.\r\n\r\nThis should be something that is done by a \"preprocessor\", maybe even related to #6508 "}}