Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Forced to pass undefined when a method accepts void or undefined #19259

Copy link
Copy link
@inad9300

Description

@inad9300
Issue body actions

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?

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already createdAn existing issue was already created

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.