8000 Overloading function signatures with mutiple optional arguments. · Issue #8000 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content

Overloading function signatures with mutiple optional arguments. #8000

@sebald

Description

@sebald

I am trying to define a function overload with mulitple optinal arguments, but can not seems to get the syntax right (see below example). Currently I am using the following signature:

function test (a:()=>void, b?:(Object|boolean), c?:boolean)

But this is misleading, because test(noop, true, true) is not a valid call signature.
Is there a way to achieve this in TS? I am having a tough time to get this to work and couldn't find a solution on SO/Google.

TypeScript Version:

1.8.9

Code

function test (a:()=>void, b?:boolean);
function test (a:()=>void, b?:Object);
function test (a:()=>void, b:Object, c?:boolean) {   
  /.../
}

const noop = () => {};

test( noop );
test( noop, {} );
test( noop, false );
test( noop, {}, false ); // Supplied parameters do not match any signature of call target.

Expected behavior:

All function calls are valid.

Actual behavior:

Function with 3 arguments is not callable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0