Description
If a method accepts void
as the type of one of its arguments, passing undefined
to it should not be explicitly required, in my opinion, as the method will receive undefined
anyway if no argument is provided.
My use case is as follows:
class C<T> {
f(a: T) {}
}
const c = new C<void>() // Or: new C<undefined>()
c.f(undefined) // OK.
c.f() // Expected 1 arguments, but got 0.
Might be an uncommon case, but what I would like to effectively indicate from the the user of class C
is the need or not to provide the argument a
. In other words, the method f()
of C
should force you to send an argument to it if the type is different than void
(so an optional argument doesn't work, unless there is a way to condition this to the argument type), but also allow you to say "I don't need an argument in f()
" (and using a default type, e.g. any
wouldn't be very type-safe, of course, so I would like to avoid this option).
What is the best possible way to achieve this for the time being? If none, does my proposal make sense?