-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
By DesignDeprecated - use "Working as Intended" or "Design Limitation" insteadDeprecated - use "Working as Intended" or "Design Limitation" instead
Description
If we define an interface:
interface IHandler {
(): number;
(): string;
}
There would be error "overloads cannot differ only by return type", which is reasonable.
However, when it comes to some situation like this:
interface IHandler<T> {
(processer: (str: string) => string): void;
(processer: (str: string) => number): void;
}
The compiler would treat (str: string) => string
and (str: string) => number
as two incompatible types, which is also reasonable but not useful enough.
I would suggest to use parameter types to defer and use return type to do type checking only.
The real situation could be Promise<T>.prototype.then
, because it accepts null as parameter, if one of the two arguments is null, it will skip the signature we would want it to match and adopts to something wrong. We may add an overload with any
as the return type of its function type, but this would mute type checking.
Metadata
Metadata
Assignees
Labels
By DesignDeprecated - use "Working as Intended" or "Design Limitation" insteadDeprecated - use "Working as Intended" or "Design Limitation" instead