Title: Overload conflicts make implementation impossible · Issue #4786 · microsoft/TypeScript · GitHub
Open Graph Title: Overload conflicts make implementation impossible · Issue #4786 · microsoft/TypeScript
X Title: Overload conflicts make implementation impossible · Issue #4786 · microsoft/TypeScript
Description: I created type definitions for Aurelia Event Aggregator as below. It compiles fine. interface Constructor
Open Graph Description: I created type definitions for Aurelia Event Aggregator as below. It compiles fine. interface Constructor
X Description: I created type definitions for Aurelia Event Aggregator as below. It compiles fine. interface Constructor<T> { new (...args: any[]): T; } declare class EventAggregator { subscribe(event: stri...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/4786
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Overload conflicts make implementation impossible","articleBody":"I created type definitions for [Aurelia Event Aggregator](http://aurelia.io/docs.html#the-event-aggregator) as below. It compiles fine.\n\n``` typescript\ninterface Constructor\u003cT> {\n new (...args: any[]): T;\n}\n\ndeclare class EventAggregator\n{\n subscribe(event: string, callback: (message: any) => void): void;\n subscribe\u003cT>(event: Constructor\u003cT>, callback: (message: T) => void): void;\n\n publish(event: string, data?: any): void;\n publish\u003cT>(event: T): void;\n}\n\nclass SomeMessage {\n constructor(public data: string) {}\n}\n\nvar ea = new EventAggregator();\n\n// event is string, message is any\nea.subscribe(\"myEvent\", message => {\n console.log(message.anything);\n});\n\n// event is class constructor, message is instance of class\nea.subscribe(SomeMessage, message => {\n console.log(message.data);\n});\n\n// event is string, message is any \nea.publish(\"myEvent\", { anything: 1 });\n\n// event is class instance\nea.publish(new SomeMessage(\"\"));\n```\n\nEven though it is possible to define declarations for this class, it is impossible to implement it in TypeScript. The following produces errors, and I can't figure how to fix it.\n\n``` typescript\ninterface Constructor\u003cT> {\n new (...args: any[]): T;\n}\n\nclass EventAggregator\n{\n subscribe(event: string, callback: (message: any) => void): void;\n subscribe\u003cT>(event: Constructor\u003cT>, callback: (message: T) => void): void {\n }\n\n publish(event: string, data?: any): void;\n publish\u003cT>(event: T): void {\n }\n}\n\nclass SomeMessage {\n constructor(public data: string) {}\n}\n\nvar ea = new EventAggregator();\n\n// event is string, message is any\nea.subscribe(\"myEvent\", message => {\n console.log(message.anything);\n});\n\n// event is class constructor, message is instance of class\nea.subscribe(SomeMessage, message => {\n console.log(message.data);\n});\n\n// event is string, message is any \nea.publish(\"myEvent\", { anything: 1 });\n\n// event is class instance\nea.publish(new SomeMessage(\"\"));\n```\n\nIs this a bug?\n\nHere's the original JS source (ES6) for reference: [aurelia/event-aggregator](https://github.com/aurelia/event-aggregator/blob/master/src/index.js)\n","author":{"url":"https://github.com/omidkrad","@type":"Person","name":"omidkrad"},"datePublished":"2015-09-14T18:39:35Z","url":"https://github.com/microsoft/TypeScript/issues/4786"}
| 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:ca9021bf-6010-2b66-3791-8e0b2c8e7d2e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CE02:2BE220:1E3F18A:28536B1:6B0173D2 |
| html-safe-nonce | f6eeb1e13f60bd240feaad952dde772f87cd9438c3b5de722884ccac10e2c733 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRTAyOjJCRTIyMDoxRTNGMThBOjI4NTM2QjE6NkIwMTczRDIiLCJ2aXNpdG9yX2lkIjoiODg5NTI0MjE0NjQ2MjkyMTY4MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | dd0c8169b2faa47e3aa5561c3fbbb28d3daea0773d3aa52861370cf6580afd55 |
| hovercard-subject-tag | issue:106402796 |
| 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/4786/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e9e08cceac8e8386082150df945b9a43d38f94a71b6a76b806c0e71dd09ff5f3/microsoft/TypeScript/issues/4786 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e9e08cceac8e8386082150df945b9a43d38f94a71b6a76b806c0e71dd09ff5f3/microsoft/TypeScript/issues/4786 |
| og:image:alt | I created type definitions for Aurelia Event Aggregator as below. It compiles fine. interface Constructor |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | omidkrad |
| 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