-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Overload conflicts make implementation impossible #4786
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
Comments
method definition is not counted as part of the overload set. you need to 1. define an overload signature of each overload, and 2. have an implementation signature that is compatible with all the overloads. class EventAggregator {
subscribe(event: string, callback: (message: any) => void): void;
subscribe<T>(event: Constructor<T>, callback: (message: T) => void): void;
subscribe(event: string|Constructor<any>, callback: (message: any) => void): void {
}
publish(event: string, data?: any): void;
publish<T>(event: T): void;
publish(event:any): void {
}
} |
This is a common source of confusion. Can we improve the error here? If the assignability check fails could we then check assignability against the implementation signature to include more helpful error text (or have we already thrown away that context by then)? That might help people solve the issue without having to go from the IDE to StackOverflow/GitHub/etc. |
@mhegazy that worked. Thanks. Is there any way to say that a parameter can take only object instances and not class constructors, so that for example |
A hacky option: interface NotFunction {
length?: void;
}
class EventAggregator {
publish(event: string, data?: any): void;
publish<T extends NotFunction>(event: T): void;
publish(event:any): void { }
}
var e: EventAggregator;
e.publish(EventAggregator); // error
e.publish(1); // ok
e.publish(''); // ok
e.publish(new EventAggregator()); // ok |
Thank you very much. I'm closing this question. You may want to open a separate issue for improving the error message for this case. |
I created type definitions for Aurelia Event Aggregator as below. It compiles fine.
Even 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.
Is this a bug?
Here's the original JS source (ES6) for reference: aurelia/event-aggregator
The text was updated successfully, but these errors were encountered: