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
I would like to be able to instantiate a generic function type with an empty type arguments list.
It would be nice to allow this for generic types, but it's not as necessary, since a generic type is always instantiated in a type context, even if no type arguments list is given. A generic function type needs to be specifically instantiated.
π Motivating Example
Here is a generic function where a type parameter has a default. I can get use an instantiation expression to specialize it to a non-generic function.
declarefunctionfind1<T,SextendsT=T>(Ar:T[],predicate:(t:T)=>t is S): S|undefined;typeFind1Object=typeoffind1<object>;
Here is a generic function with only one type parameter. I cannot use an instantiation expression with the default for S:
declarefunctionfind2<Sextendsobject=object>(Ar:object[],predicate:(t:object)=>t is S) : S|undefined;typeFind2=typeoffind2<>;// <- this is a syntax error "Type argument list cannot be empty"
π» Use Cases
What do you want to use this for?
What shortcomings exist with current approaches?
What workarounds are you using in the meantime?
Declare an unused "dummy" type parameter so there's always a non-defaulted type argument.
Can we get this for calling the function directly also? That is: just support empty type argument lists for generic functions, if all of the type parameters have defaults. It would be weird for (f<>)() to work but for f<>() not to work.
π Search Terms
instantiation expression, empty, type arguments
β Viability Checklist
β Suggestion
I would like to be able to instantiate a generic function type with an empty type arguments list.
It would be nice to allow this for generic types, but it's not as necessary, since a generic type is always instantiated in a type context, even if no type arguments list is given. A generic function type needs to be specifically instantiated.
π Motivating Example
Here is a generic function where a type parameter has a default. I can get use an instantiation expression to specialize it to a non-generic function.
Here is a generic function with only one type parameter. I cannot use an instantiation expression with the default for
S
:π» Use Cases
Originally mentioned here: #57463 (comment)
The text was updated successfully, but these errors were encountered: