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
Task does not support covariant type args. This would be similar to ImmutableArray<T>.CastUp.
The current workaround is to simply await the task or use ContinueWith to cast.
API Proposal
public class Task<T>
{
+ public static Task<T> CastUp<TDerived>(Task<TDerived> task) where TDerived : class?, T;
}
public struct ValueTask<T>
{
+ public static ValueTask<T> CastUp<TDerived>(ValueTask<TDerived> task) where TDerived : class?, T;
}
Activity
huoyaoyuan commentedon Aug 2, 2023
A covariant interface may be useful for
Task, but forValueTaskaCastUpmay help better.ericstj commentedon Aug 8, 2023
cc @stephentoub
bartonjs commentedon Sep 8, 2026
Video
Looks good as proposed.
hez2010 commentedon Nov 3, 2026
We now have another motivating case that can be greatly helped by target-type generic inference. cc: @MadsTorgersen