-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
Description
TypeScript Version: 3.4.0-dev.201xxxxx
Search Terms:
"mapped types", "overload", "intersection"
Code
type ReturnObjects<T> = {
[K in keyof T]: T[K] extends ((...args: any[]) => any) ?
T[K] & Returnable<T[K]> :
never
}
type Returnable<Fun extends (...args: any[]) => any> = {
returnValue(val: ReturnType<Fun>): void;
}
interface I {
f(): string;
f(x: any): number;
}
let argsObj: ReturnObjects<I>;
argsObj.f.returnValue(1) // OK
argsObj.f.returnValue('1') // ERROR?!```Expected behavior:
argsObj.f.returnValue('1') should not cause a type error
Actual behavior:
argsObj.f.returnValue('1') causes a type error
Related Issues: Couldn't find anything
Note that if I switch the order of the interface, it will only expect the other overload. I believe that typescript is overriding the previous value and not intersecting them
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed