You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
typeDelegate<T>=()=>T;functionexecuteGeneric<X,DelegateTextendsDelegate<X>>(delegate: DelegateT): ReturnType<DelegateT>{//Type 'X' is not assignable to type 'ReturnType<DelegateT>'.constx: ReturnType<typeofdelegate>=delegate();//Type 'X' is not assignable to type 'ReturnType<DelegateT>'.consty: ReturnType<DelegateT>=delegate();//Type 'X' is not assignable to type 'ReturnType<DelegateT>'.returndelegate();}
Expected behavior:
Return successfully.
Intuitively, to me,
delegate is of typeDelegateT.
ReturnType<DelegateT> and ReturnType<typeof delegate> should be the same
However,
Actual behavior:
Type 'X' is not assignable to type 'ReturnType<DelegateT>'.
TypeScript Version: Version 2.9.0-dev.20180516
Search Terms: generic function returntype
I couldn't think of a good title for this,
Code
Expected behavior:
Return successfully.
Intuitively, to me,
delegateis of typeDelegateT.ReturnType<DelegateT>andReturnType<typeof delegate>should be the sameHowever,
Actual behavior:
Type 'X' is not assignable to type 'ReturnType<DelegateT>'.Playground Link: Here
Related Issues: