Skip to content

Allows you to configure functions not to pass arguments when they can be undefined #56632

Not planned
@guaijie

Description

@guaijie

πŸ”Ž Search Terms

"undefined", "void", "optional", "no arguments", "rules"

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about typescript

⏯ Playground Link

No response

πŸ’» Code

const fn1= (param: undefined | number) => {}
const fn2 = (param: undefined | number) => {}

πŸ™ Actual behavior

fn1(undefined) // success
fn1() // fail
fn2(undefined) //success
fn2() // success

πŸ™‚ Expected behavior

fn1(undefined) // success
fn1() // success 
fn2(undefined) //success
fn2() // success

Additional information about the issue

No response

Activity

fatcerberus

fatcerberus commented on Dec 1, 2023

@fatcerberus

This is what optional parameters are for

const fn1 = (param?: number) => {};
fn1(undefined);  // works
fn1();           // also works
jcalz

jcalz commented on Dec 1, 2023

@jcalz
Contributor

Duplicate of #12400

typescript-bot

typescript-bot commented on Dec 4, 2023

@typescript-bot
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jcalz@fatcerberus@RyanCavanaugh@typescript-bot@guaijie

        Issue actions

          Allows you to configure functions not to pass arguments when they can be undefined Β· Issue #56632 Β· microsoft/TypeScript