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
constf1=(arg: void)=>{};constr1=f1();// no errorconstf2=<T=void>(arg: T)=>{};constr2=f2();// Expected 1 arguments, but got 0, An argument for 'arg' was not provided.typeF<T=void>=(arg: T)=>void;constf3: F=arg=>{};constr3=f3();// no errorconstf4=<T=undefined>(arg: Textendsundefined ? void : T)=>{};constr4=f4<undefined>();// Expected 1 arguments, but got 0, An argument for 'arg' was not provided.classKlass<T=void>{constructor(arg: T){}f(arg: T){return;}}constk=newKlass();// Expected 1 arguments, but got 0, An argument for 'arg' was not provided.constr5=k.f();// no error
π Actual behavior
I would like to have / need some tools to control whether or not a function argument is optional based on context given via generics.
In most cases I still get the TS error Expected 1 arguments, but got 0, where I wouldn't expect an error.
But I could find some (edge) cases where it's working tho, so at least the behaviour is inconsistent (see the example above)
π Expected behavior
So in case the type of a function argument resolves into void (via a generic type or via conditional resolution), it should be possible to call that function without arguments without getting a TS error.
π Search Terms
"function argument optional via generic"
π Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about "optional function arguments via generics"
β― Playground Link
Playground Link
π» Code
π Actual behavior
I would like to have / need some tools to control whether or not a function argument is optional based on context given via generics.
In most cases I still get the TS error
Expected 1 arguments, but got 0
, where I wouldn't expect an error.But I could find some (edge) cases where it's working tho, so at least the behaviour is inconsistent (see the example above)
π Expected behavior
So in case the type of a function argument resolves into
void
(via a generic type or via conditional resolution), it should be possible to call that function without arguments without getting a TS error.Additional information about the issue
Partially related #29131
The text was updated successfully, but these errors were encountered: