Open
Description
TypeScript Version: Version 2.9.0-dev.20180516
Search Terms: generic function returntype
I couldn't think of a good title for this,
Code
type Delegate<T> = () => T;
function executeGeneric<
X,
DelegateT extends Delegate<X>
>(delegate: DelegateT): ReturnType<DelegateT> {
//Type 'X' is not assignable to type 'ReturnType<DelegateT>'.
const x: ReturnType<typeof delegate> = delegate();
//Type 'X' is not assignable to type 'ReturnType<DelegateT>'.
const y: ReturnType<DelegateT> = delegate();
//Type 'X' is not assignable to type 'ReturnType<DelegateT>'.
return delegate();
}
Expected behavior:
Return successfully.
Intuitively, to me,
delegate
is of typeDelegateT
.ReturnType<DelegateT>
andReturnType<typeof delegate>
should be the same
However,
Actual behavior:
Type 'X' is not assignable to type 'ReturnType<DelegateT>'.
Playground Link: Here
Related Issues: