Title: Suggestion: implicitly infer parameter types for the implementation signature of an overloaded method · Issue #7763 · microsoft/TypeScript · GitHub
Open Graph Title: Suggestion: implicitly infer parameter types for the implementation signature of an overloaded method · Issue #7763 · microsoft/TypeScript
X Title: Suggestion: implicitly infer parameter types for the implementation signature of an overloaded method · Issue #7763 · microsoft/TypeScript
Description: The current pattern for method overloading in a class is: class Example { // Overload signatures: func(param1: number, param2: string): number; func(param1: number[], param2: boolean[]): number[]; // Actual method implementation: func(pa...
Open Graph Description: The current pattern for method overloading in a class is: class Example { // Overload signatures: func(param1: number, param2: string): number; func(param1: number[], param2: boolean[]): number[]; ...
X Description: The current pattern for method overloading in a class is: class Example { // Overload signatures: func(param1: number, param2: string): number; func(param1: number[], param2: boolean[]): number[]; ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/7763
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Suggestion: implicitly infer parameter types for the implementation signature of an overloaded method","articleBody":"The current pattern for method overloading in a class is:\n\n``` ts\nclass Example {\n // Overload signatures:\n func(param1: number, param2: string): number;\n func(param1: number[], param2: boolean[]): number[];\n\n // Actual method implementation:\n func(param1: number | number[], param2: string | boolean[]): number | number[] {\n ...\n }\n}\n```\n\nHowever the implementation signature is only in practice beneficial for parameter references within the body of the function. E.g., even if the parameter types of the implementation signature were, say, all set to `any`:\n\n``` ts\nfunc(param1: any, param2: any): any {\n ...\n}\n```\n\nA caller is still bound by the overload signatures:\n\n``` ts\nlet example = new Example();\nexample.func(\"ABC\", 123); // Error! no overload of 'func' matches the arguments\n```\n\n**Suggestion:**\n\nThe parameter and return type of the implementation signature could be implicitly inferred if they are not given an explicit type:\n\n``` ts\nclass Example {\n func(param1: number, param2: string): number;\n func(param1: number[], param2: boolean[]): number[];\n\n func(param1, param2) {\n let x = param1; // type of x is number | number[]\n let y = param2; // type of y is string | boolean[]\n\n return \"ABC\"; // Error: return type has been implicitly inferred to number | number[] \n }\n}\n```\n\nHaving this would make it less cumbersome to define and maintain overloaded methods.\n\nHas this ever been discussed before? and if so, what were the arguments against it?\n","author":{"url":"https://github.com/malibuzios","@type":"Person","name":"malibuzios"},"datePublished":"2016-04-01T12:23:19Z","url":"https://github.com/microsoft/TypeScript/issues/7763"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:02fcf130-2814-abcd-9954-24dcb20f8b58 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D740:1F2D:13F2EB5:1934F9D:6B015F64 |
| html-safe-nonce | 2590ff374140ab4f7a93e9cada95fd5cdad311e3d300effd0c19a29729001a6d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENzQwOjFGMkQ6MTNGMkVCNToxOTM0RjlEOjZCMDE1RjY0IiwidmlzaXRvcl9pZCI6Ijg2MDA2MTEyMDEyMjk2MDM2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 3a1bda197ce3d4c9d2823a9911f5dbda1c7032c2e776309c153ce4edbe93f4e9 |
| hovercard-subject-tag | issue:145167400 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/7763/issue_layout |
| twitter:image | https://opengraph.githubassets.com/18974d7fe1b8f8b82eca479ac2545d7f35aea012113bff10b6260fc75408c4c1/microsoft/TypeScript/issues/7763 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/18974d7fe1b8f8b82eca479ac2545d7f35aea012113bff10b6260fc75408c4c1/microsoft/TypeScript/issues/7763 |
| og:image:alt | The current pattern for method overloading in a class is: class Example { // Overload signatures: func(param1: number, param2: string): number; func(param1: number[], param2: boolean[]): number[]; ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | malibuzios |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width